Serial Communications: From UART to I2C Protocols

ece 3567 ece 3567 n.w
1 / 42
Embed
Share

Explore the evolution of serial communications from UART to I2C protocols, including insights on RS-232 standards and modem cables. Learn about the key components and transmission methods used in serial data transfer for efficient communication between devices.

  • Serial Communications
  • UART Protocol
  • RS-232 Standard
  • I2C Protocol
  • Modem Cables

Uploaded on | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. ECE 3567 ECE 3567 Lab 5 Lab 5 Serial Communications Serial Communications Dr. Gregg J Chapman Autumn 2024 1

  2. A Brief History of Serial Communications MODEM 2

  3. RS-232 STANDARD 3

  4. FULL MODEM Cable 4

  5. Serial Communications Interface (RS-232) SCI MODEM CABLE 5

  6. NULL MODEM CABLE 6

  7. UART - Universal Asynchronous Receiver Transmitter That's what describes UART. No voltage level, so you can have it at 3.3 V or 5 V, whichever your microcontroller uses. Note that the microcontrollers which want to communicate via UART have to agree on the transmission speed, the bit-rate, as they only have the start bits falling edge to synchronize. That's called asynchronous communication. For long distance communication (That doesn't have to be hundreds of meters) the 5 V UART is not very reliable, that's why it's converted to a higher voltage, typically +12 V for a "0" and - 12 V for a "1". The data format remains the same. Then you have RS-232 (which you actually should call EIA-232, but nobody does.) The timing dependency is one of the big drawbacks of UART 7

  8. UART - Universal Asynchronous Receiver Transmitter one of the most used serial protocols. Most controllers have a hardware UART on board. It uses a single data line for transmitting and one for receiving data. Most often 8-bit data is transferred, as follows: 1 start bit (low level), 8 data bits and 1 stop bit (high level). The low level start bit and high level stop bit mean that there's always a high to low transition to start the communication. 8

  9. I2C - Inter-Integrated Circuit ( pronounced "I squared C") I2C uses only 2 wires, one for the clock (SCL) and one for the data (SDA). That means that master and slave send data over the same wire, again controlled by the master who creates the clock signal. I2C doesn't use separate Slave Selects to select a particular device, but has addressing. The first byte sent by the master holds a 7 bit address and a read/write bit, indicating whether the next byte(s) will also come from the master or should come from the slave. After each byte, the receiver must send a "0" to acknowledge the reception of the byte ACK If the master wants to write a byte, the same process repeats If the master wants to receive data it only generates the clock pulses. The slave has to take care that the next bit is ready when the clock pulse is given. 9

  10. Serial Peripheral Interface 10

  11. Which Serial Protocol is Best? Which Serial Protocol is Best? I2C UART SPI Easy to chain many devices. Complex as device increases Complexity Simple Faster than UART Speed Slowest Fastest 48-100 Mbps 1.5 Mbps 3.4 Mbit/s 11

  12. Project Set Project Set- -up up Create a new project for Lab 5, download all files from the website and Create a new project for Lab 5, download all files from the website and copy them into the project. copy them into the project. 12

  13. Whats New? What s New? 1. 3567.h 2. myGpio.c 3. myClocks.c 4. myUart.c 5. Command.c 6. With additions to Display.c 13

  14. Where are all the variables? Where are all the variables? 14

  15. Adding UART Communications Adding UART Communications 15

  16. Checkpoint #1 Checkpoint #1 Compile the program and Compile the program and demonstrate that it cycles through the LED colors. demonstrate that it cycles through the LED colors. 16

  17. Project Set Project Set- -up up 1. Delete 1. Delete update_RGB update_RGB() from main(). copy them into the project. () from main(). copy them into the project. 2. Comment out the following code at the beginning of 2. Comment out the following code at the beginning of update_RGB update_RGB() () 17

  18. Connecting the Serial Communications Connecting the Serial Communications 18

  19. You can also use the Terminal You can also use the Terminal inside CCS: inside CCS: click choose one

  20. When you run the project, the following When you run the project, the following messages will appear in the Terminal window: messages will appear in the Terminal window:

  21. Checkpoint #2 Checkpoint #2 Demonstrate the ECE 3567 Start Demonstrate the ECE 3567 Start- - up Message on the Terminal up Message on the Terminal 21

  22. The main() function The main() function

  23. Initializes UART Communications on the MCU Initializes UART Communications on the MCU

  24. myUart.c myUart.c

  25. Command.c Command.c 1. Command_Handler (Already written) 2. parse_Command (You will write this) 25

  26. The Command Handler The Command Handler Data is in an array called val Most commands are 2 characters Setpoint commands for feedback are up to 6 characters Communications are interrupt driven Gets set in myUart_readBuf

  27. Display.c Display.c 1. displayTemp() Turn on degree symbol and F in pos6 for Fahrenheit 2. displayVolts() Turn on the decimal point and V in pos6 for Volts 27

  28. The Three Modes The Three Modes 1. LED Test Mode 2. Temperature Mode 3. RC Voltage Mode 28

  29. Lab 5 Lab 5 1. Write parse_Command() to: 1. Read the first two characters from the val[ ] array and convert to a 2-character command. 2. If length is >2, convert val[2], val[3], and val[4] to a single 3-difit number. val[5] is currently not used. 3. Reset length to 2, and clear val[ ]; 4. Create a SWITCH statement for Command and place actions for the command under each case: Implement the following Commands: 1. LE Places the software in LED Test Mode. LED off. 2. RE Places the software in RC Voltage Mode. Writes 2.50V to the LCD 3. TE Places the software in Temperature Mode. Writes 75.0 F to the LCD 4. LH Makes the LED FLASH RED if you are in LED Test Mode 5. LR Makes the LED RED if you are in LED Test Mode 6. LO Makes the LED ORANGE if you are in LED Test Mode 7. LY Makes the LED Yellow if you are in LED Test Mode 8. LG Makes the LED Green if you are in LED Test Mode 9. LB Makes the LED Blue if you are in LED Test Mode 10. LV Makes the LED Violet if you are in LED Test Mode 11. LC Makes the LED FLASH Violet if you are in LED Test Mode 29

  30. Flashing Flashing 1. Easiest way to do this is alternate the P2DIR and P3DIR bits for each of the RGB elements in the 1 Second delay section of the main loop 2. NOTE: If you exit the FLASH mode when the LED is OFF, it won t ever turn on again. To solve the problem use: if(Flash == TRUE) { //Alternate the DIRs } else { //Set the DIRs back to outputs } 30

  31. Building a Command Building a Command 31

  32. The Commands The Commands 1. Consist of 2 alphabetical characters 2. Letters used must be #defined in 3567.h 3. Two character commands must be #defined as a unique number in 3567.h 32

  33. The Commands The Commands 4. The Command_Handler loads ASCII characters into an array called val[ ] 5. val[0] and val[1] contain the command characters 6. For two commands, TS and RS, val[2], val[3], val[4], and val[5] contain numerical characters a. For TS the number is a temperature setpoint for regulation. The 2 most significant digits are displayed before the decimal, the last two digits are not displayed on the LCD in this lab. b. For RS the number is a setpoint for voltage regulation in millivolts. Only the 3 most significant digits are displayed, one before the decimal and two after. 33

  34. parse_Command parse_Command voidparse_Command() { if(val[0] == A) { if(val[1] == B ) Command = AB; elseif(val[1] == D) Command = AD; } elseif(val[0] == B) { if(val[1] == E ) Command = BE; elseif(val[1] == D) Command = BD; } else { Command = NULL; myUart_writeBuf( BACKCHANNEL_UART, "UNKNOWN COMMAND ", NULL, CRLF ); New_Data=0; myUart_writeBuf( BACKCHANNEL_UART, "", NULL, CRLF ); // Ask for the next Command } if(length >=5) // Included for SetPoint Command data { New_Data = 0; New_Data = (val[2]-48)*100 + (val[3]-48)*10 + (val[4]-48); length = 2; val[2]=0; val[3]=0; val[4]=0; } first character second character Command Unpack the data and convert to decimal numbers

  35. Still in Still in parse_Command parse_Command /************************************************** Act on the Command *************************************************/ switch(Command) { case AB: // Act on Command AB break; case BD: // Act on Command BD break; case XX: // etc. break; default: break; } Command = NULL; myUart_writeBuf( BACKCHANNEL_UART, "Please enter the next Command Code: ", NULL, CRLF ); return; } All actions for the Command go here

  36. LE Command LE Command 1. Enable LED_Test_Mode 2. Disable Temp_Mode and RC_Voltage_Mode 3. Clear the LCD 4. Turn off the LED 5. Set Flash to FALSE 6. Set LED_Color to No_Color

  37. Lx Commands Lx Commands 1. Only perform if LED_Test_Mode is TRUE 2. Set LED_Color to the appropriate label 3. Flash is FALSE for everything except LH an LC

  38. Checkpoint #3 Checkpoint #3 Demonstrate the LED Test Mode Demonstrate the LED Test Mode (LE, LH, LR, LO, LY, LG, LB, LV, LC) (LE, LH, LR, LO, LY, LG, LB, LV, LC) 38

  39. TE Command TE Command 1. Enable Temp_Mode 2. Disable RC_Voltage_Mode and LED_Test_Mode 3. Clear the LCD 4. Turn off the LED 5. Set Flash to FALSE 6. Set LED_Color to No_Color 7. Set deg = 750 8. Call displayTemp() (NOTE: You must write this) 9. There will be additions to this in a latter lab

  40. Checkpoint #4 Checkpoint #4 Demonstrate the Temperature Demonstrate the Temperature Mode Command Mode Command 40

  41. RE Command RE Command 1. Enable RC_Voltage_Mode 2. Disable Temp_Mode and LED_Test_Mode 3. Clear the LCD 4. Turn off the LED 5. Set Flash to FALSE 6. Set LED_Color to No_Color 7. Set volts = 2500 8. Call displayVolts() (NOTE: You must write this) 9. There will be additions to this in a latter lab

  42. Checkpoint #5 Checkpoint #5 Demonstrate the RC Voltage Demonstrate the RC Voltage Mode Command Mode Command 42

More Related Content