Beruflich Dokumente
Kultur Dokumente
CSE 3442/5442
1
Serial Communication
Digital devices that need to communicate can do that through serial or parallel communication Serial communication requires less wires (and less pins), and due to crosstalk on long cables, can reach higher total bandwidths. Serial communication requires as little as two wires: one for data and one for common ground. In order to enable full-duplex communication, we can introduce one more data line, and thus have a unique data line in both directions. If clock is not transmitted on a separate wire, then we are talking about asynchronous serial communication
3
Overhead? time
LSB
As microcontrollers usually output 0V for 0 and 1-5V for 1, external voltage level converters are needed. This requires up conversion. MAX232 is the most common conversion circuit.
How About Those Other RS232 Pins? In addition to RxD, TxD and ground, there are many other signals on RS232 connectors (that are not usually used on microcontrollers) They include: shielding, !RTS and !CTS for flow control, DTR and DSR to indicate to the other side that the terminal or the modem is ready, DCD so the modem can tell the computer if a line is available, etc.
7
PIC18 EUSART
The enhanced universal synchronous, asynchronous receiver transmitter is one peripheral module on the PIC18 that can be used for serial communication. Can be configured as:
ART full duplex SRT, master SRT, slave
10
11
Receiving on UART
RX pin needs to be set as input Baud rate has to be set. USART peripheral needs to be enabled (RCSTA.SPEN) Receiving on UART needs to be enabled (RCSTA.CREN) The PIR1.RCIF flag will be raised by the microcontroller if it received a valid byte. The user needs to copy the received byte out of RCREG. This will automatically reset RCIF. Then the microcontroller can receive the next byte without overwriting RCREG (and thus the user loosing data).
12
13
14
Transmitting on UART
TXREG is an 8-bit register that the user needs to load up with the data to be transmitted. TSR is a shift register that is not user accessible. The program needs to load a byte to be transmitted into TXREG. If TSR is empty this same byte will be loaded into TSR and the TXREG is cleared (to avoid sending the same byte twice). The program can then load another value into the TXREG. After loading the TXREG, the program needs to tell the microcontroller that transmission should start by flipping the TXEN bit in the TXSTA control register. The TXIF (interrupt flag) in PIR1 is set by the microcontroller to notify the program that the last byte has been sent. The program can then load the next byte into TXREG. TXIF cannot be reset from software, it is cleared one instruction cycle after loading the TXREG. (remember circular buffers!)
15
16
17
We are briefly going to cover these two bus technologies without going into detail how they can be used in the PIC18.
19
SPI
SPI can be either 3-wire or 4-wire (they are not compatible). SDI (serial data in), SDO (serial data out), SCLK, and CE (chip enable) make up the 4 signals. 3-wire has SDI and SDO connected. We have seen the SPI module already with the DAC. SPI frame format contains addresses in addition to data
20
21
22
I2C
Common bus speeds are 10kbps and 100kbps but can be arbitrary. Master node generates clock; four potential modes: master transmits, master receives, slave transmits, slave receives. Control to the lines is usually open-collector (open-drain). Seven, or ten bits are used for addressing peripheral, then data is transmitted.
23
Summary
Communicating to external peripherals, other microcontrollers, or a computer are must in embedded systems. Microcontrollers usually provide several different serial communication methods for the above. UART is probably the most common technique used in point-to-point communication, however synchronous communication may be used as well. SPI and I2C are two bus standards that allow several microcontrollers or peripheral devices to be connected to the same bus.
24