SlideShare a Scribd company logo
1 of 13
Download to read offline
Using the UART in Microchip PIC18F
Microcontrollers
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro Using the UART in PIC18F Family
UART in MCUs
UART = Universal Asynchronous Receiver/Trasmitter
It is commonly referred as serial port
It is a peripheral for point-to-point communication between
two devices
Communication occurs in serial, i.e. one bit at time
Two communication PINs: RX and TX
Corrado Santoro Using the UART in PIC18F Family
UART trasmission basics
When no transmission, the line is set to Logical “1”
Then the software triggers the trasmission of a byte
(e.g. “C”, hexcode 43, binary 0100 0011
First a Logical “0” is transmitted, called start bit
Then the byte is transmitted LSB first
An additional parity bit may follow (not in the example); it
used for error checking
One or two stop bits (Logical “1”) ends the transmission
Corrado Santoro Using the UART in PIC18F Family
UART trasmission parameters
The following parameters must be set in the UART hardware:
transmission speed, in bps = Bit Per Second or baud
number of bits per character, usually 8
presence/absence of partity bit, usually absent
number of stop bits, usually 1
A setting 19200,8,N,1 means:
speed = 19200 bit-per-second;
bits = 8;
parity = None;
stop bits = 1.
Corrado Santoro Using the UART in PIC18F Family
UART in the PIC18F25K22
From the datasheet:
Two different UART
The TX line of the UART1 is shared with RC6
The RX line of the UART1 is shared with RC7
The TX line of the UART2 is shared with RB6
The RX line of the UART2 is shared with RB7
Basic registers per UARTx (“x” is the UART number):
TXSTAx, configuration of the transmitter
RCSTAx, configuration of the receiver
BAUDCONx, configuration of the baud rate (speed)
generator
SPBRGx, baud rate (speed) generator value
Corrado Santoro Using the UART in PIC18F Family
The Baud Rate Generator
It is divisor driven from system clock frequency (FOSC).
It is controlled by the following bits/registers:
SPBRGHx:SPBRGx: the divisor value to be applied to
FOSC to obtain the desired baud rate
BAUDCONxbits.BRG16, a bit which indicates whether the
divisor value uses 8 or 16 bits
TXSTAxbits.BRGH, a bit which indicates if we are using a
high-speed baud date
A formula exists to compute the divisor value, but... Microchip
provides very usefull tables!
Corrado Santoro Using the UART in PIC18F Family
Setting the Baudrate generator
Corrado Santoro Using the UART in PIC18F Family
Setting the UART
UART Setup
...
// setup UART
TRISCbits.TRISC6 = 0; // TX as output
TRISCbits.TRISC7 = 1; // RX as input
TXSTA1bits.SYNC = 0; // Async operation
TXSTA1bits.TX9 = 0; // No tx of 9th bit
TXSTA1bits.TXEN = 1 // Enable transmitter
RCSTA1bits.RX9 = 0; // No rx of 9th bit
RCSTA1bits.CREN = 1; // Enable receiver
RCSTA1bits.SPEN = 1; // Enable serial port
// Setting for 19200 BPS
BAUDCON1bits.BRG16 = 0; // Divisor at 8 bit
TXSTA1bits.BRGH = 0; // No high-speed baudrate
SPBRG1 = 51; // divisor value for 19200
Corrado Santoro Using the UART in PIC18F Family
The UART Transmitter
Transmission is triggered by loading the byte into TXREGx;
The byte is loaded into the shift-register and the TXxIF is set;
The byte is “shifted-out” (transmitted) and, when transmission is
completed TXSTAxbits.TRMT is set;
A new byte can be loaded into TXREG for a new transmission.
Corrado Santoro Using the UART in PIC18F Family
Transmitting a byte
Basic transmission
// wait the end of transmission
while (TXSTA1bits.TRMT == 0) {};
TXREG1 = new data; // start sending the new byte
... or, you can use directly the printf function, provided that you
implement a proper putch(char c) function, that is then called
by printf for each character to send.
Using printf
void putch(char c) {
// wait the end of transmission
while (TXSTA1bits.TRMT == 0) {};
TXREG1 = c; // send the new byte
}
...
printf("Hello world!!");
...
Corrado Santoro Using the UART in PIC18F Family
The UART Receiver
When a byte is received it is automatically loaded into RCREGx;
When reception is completed RCxIF is set, which can be tested (using
polling or interrupt);
Reading RCREGx causes RCxIF to be automatically reset;
But some errors may occur and must be handled:
Overrun error, RCSTAxbits.OERR==1, a new data is received
but RCREGx has not previously read;
Framing error, RCSTAxbits.FERR==1, the data is not properly
“framed”, i.e. the stop bit(s) are not valid.
Corrado Santoro Using the UART in PIC18F Family
Reading a character
UART Char Reading
char read char(void)
{
while (PIR1bits.RC1IF == 0) { // wait for char
if (RCSTA1bits.OERR == 1) {
RCSTA1bits.OERR = 0; // clear overrun if it occurs
RCSTA1bits.CREN = 0;
RCSTA1bits.CREN = 1;
}
}
return RCREG1;
}
Corrado Santoro Using the UART in PIC18F Family
Using the UART in Microchip PIC18F
Microcontrollers
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro Using the UART in PIC18F Family

More Related Content

What's hot

Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsCorrado Santoro
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16Ramadan Ramadan
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVRHamdy Fouad
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmelRuderocker Billy
 
Pt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testPt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testrajbabureliance
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorialNabil Chouba
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converterMohamed Ali
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 
Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012cairo university
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 

What's hot (20)

Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16
 
Interrupts at AVR
Interrupts at AVRInterrupts at AVR
Interrupts at AVR
 
Uart
UartUart
Uart
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Microcontroller Instruction Set atmel
Microcontroller Instruction Set atmelMicrocontroller Instruction Set atmel
Microcontroller Instruction Set atmel
 
Class8
Class8Class8
Class8
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Interrupt
InterruptInterrupt
Interrupt
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
89c5131datasheet
89c5131datasheet89c5131datasheet
89c5131datasheet
 
Lecture 2 timers, pwm, state machine IN PIC
Lecture 2   timers, pwm, state machine IN PIC Lecture 2   timers, pwm, state machine IN PIC
Lecture 2 timers, pwm, state machine IN PIC
 
Pt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testPt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-test
 
Uart VHDL RTL design tutorial
Uart VHDL RTL design tutorialUart VHDL RTL design tutorial
Uart VHDL RTL design tutorial
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
 
Lecture7
Lecture7Lecture7
Lecture7
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012Lecture 5 (system clock crossbar and gpio) rv012
Lecture 5 (system clock crossbar and gpio) rv012
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 

Similar to UART MCU

A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...Kevin Mathew
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
Synthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft CoreSynthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft Coreijsrd.com
 
PIC16F877A interfacing with LCD
PIC16F877A interfacing with LCDPIC16F877A interfacing with LCD
PIC16F877A interfacing with LCDsunil polo
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)cairo university
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart socSatyam Sharma
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGTotal Project Solutions
 
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...IJERA Editor
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfHebaEng
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerJhemi22
 

Similar to UART MCU (20)

020419.pdf
020419.pdf020419.pdf
020419.pdf
 
UART
UARTUART
UART
 
Tutorial
TutorialTutorial
Tutorial
 
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
A Robust UART Architecture Based on Recursive Running Sum Filter for Better N...
 
Uart
UartUart
Uart
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
Synthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft CoreSynthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft Core
 
Ec8791 lpc2148 uart
Ec8791 lpc2148 uartEc8791 lpc2148 uart
Ec8791 lpc2148 uart
 
PIC16F877A interfacing with LCD
PIC16F877A interfacing with LCDPIC16F877A interfacing with LCD
PIC16F877A interfacing with LCD
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)
 
Uart
UartUart
Uart
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart soc
 
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...
Achieving Reduced Area and Power with Multi Bit Flip-Flop When Implemented In...
 
Uart wiki
Uart wikiUart wiki
Uart wiki
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Micro lec note2 (1)
Micro lec note2 (1)Micro lec note2 (1)
Micro lec note2 (1)
 

More from Corrado Santoro

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Corrado Santoro
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsCorrado Santoro
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Corrado Santoro
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015 Corrado Santoro
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converterCorrado Santoro
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersCorrado Santoro
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...Corrado Santoro
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous RobotsCorrado Santoro
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolCorrado Santoro
 

More from Corrado Santoro (13)

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUs
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
Pillole di C++
Pillole di C++Pillole di C++
Pillole di C++
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA tool
 

UART MCU

  • 1. Using the UART in Microchip PIC18F Microcontrollers Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro Using the UART in PIC18F Family
  • 2. UART in MCUs UART = Universal Asynchronous Receiver/Trasmitter It is commonly referred as serial port It is a peripheral for point-to-point communication between two devices Communication occurs in serial, i.e. one bit at time Two communication PINs: RX and TX Corrado Santoro Using the UART in PIC18F Family
  • 3. UART trasmission basics When no transmission, the line is set to Logical “1” Then the software triggers the trasmission of a byte (e.g. “C”, hexcode 43, binary 0100 0011 First a Logical “0” is transmitted, called start bit Then the byte is transmitted LSB first An additional parity bit may follow (not in the example); it used for error checking One or two stop bits (Logical “1”) ends the transmission Corrado Santoro Using the UART in PIC18F Family
  • 4. UART trasmission parameters The following parameters must be set in the UART hardware: transmission speed, in bps = Bit Per Second or baud number of bits per character, usually 8 presence/absence of partity bit, usually absent number of stop bits, usually 1 A setting 19200,8,N,1 means: speed = 19200 bit-per-second; bits = 8; parity = None; stop bits = 1. Corrado Santoro Using the UART in PIC18F Family
  • 5. UART in the PIC18F25K22 From the datasheet: Two different UART The TX line of the UART1 is shared with RC6 The RX line of the UART1 is shared with RC7 The TX line of the UART2 is shared with RB6 The RX line of the UART2 is shared with RB7 Basic registers per UARTx (“x” is the UART number): TXSTAx, configuration of the transmitter RCSTAx, configuration of the receiver BAUDCONx, configuration of the baud rate (speed) generator SPBRGx, baud rate (speed) generator value Corrado Santoro Using the UART in PIC18F Family
  • 6. The Baud Rate Generator It is divisor driven from system clock frequency (FOSC). It is controlled by the following bits/registers: SPBRGHx:SPBRGx: the divisor value to be applied to FOSC to obtain the desired baud rate BAUDCONxbits.BRG16, a bit which indicates whether the divisor value uses 8 or 16 bits TXSTAxbits.BRGH, a bit which indicates if we are using a high-speed baud date A formula exists to compute the divisor value, but... Microchip provides very usefull tables! Corrado Santoro Using the UART in PIC18F Family
  • 7. Setting the Baudrate generator Corrado Santoro Using the UART in PIC18F Family
  • 8. Setting the UART UART Setup ... // setup UART TRISCbits.TRISC6 = 0; // TX as output TRISCbits.TRISC7 = 1; // RX as input TXSTA1bits.SYNC = 0; // Async operation TXSTA1bits.TX9 = 0; // No tx of 9th bit TXSTA1bits.TXEN = 1 // Enable transmitter RCSTA1bits.RX9 = 0; // No rx of 9th bit RCSTA1bits.CREN = 1; // Enable receiver RCSTA1bits.SPEN = 1; // Enable serial port // Setting for 19200 BPS BAUDCON1bits.BRG16 = 0; // Divisor at 8 bit TXSTA1bits.BRGH = 0; // No high-speed baudrate SPBRG1 = 51; // divisor value for 19200 Corrado Santoro Using the UART in PIC18F Family
  • 9. The UART Transmitter Transmission is triggered by loading the byte into TXREGx; The byte is loaded into the shift-register and the TXxIF is set; The byte is “shifted-out” (transmitted) and, when transmission is completed TXSTAxbits.TRMT is set; A new byte can be loaded into TXREG for a new transmission. Corrado Santoro Using the UART in PIC18F Family
  • 10. Transmitting a byte Basic transmission // wait the end of transmission while (TXSTA1bits.TRMT == 0) {}; TXREG1 = new data; // start sending the new byte ... or, you can use directly the printf function, provided that you implement a proper putch(char c) function, that is then called by printf for each character to send. Using printf void putch(char c) { // wait the end of transmission while (TXSTA1bits.TRMT == 0) {}; TXREG1 = c; // send the new byte } ... printf("Hello world!!"); ... Corrado Santoro Using the UART in PIC18F Family
  • 11. The UART Receiver When a byte is received it is automatically loaded into RCREGx; When reception is completed RCxIF is set, which can be tested (using polling or interrupt); Reading RCREGx causes RCxIF to be automatically reset; But some errors may occur and must be handled: Overrun error, RCSTAxbits.OERR==1, a new data is received but RCREGx has not previously read; Framing error, RCSTAxbits.FERR==1, the data is not properly “framed”, i.e. the stop bit(s) are not valid. Corrado Santoro Using the UART in PIC18F Family
  • 12. Reading a character UART Char Reading char read char(void) { while (PIR1bits.RC1IF == 0) { // wait for char if (RCSTA1bits.OERR == 1) { RCSTA1bits.OERR = 0; // clear overrun if it occurs RCSTA1bits.CREN = 0; RCSTA1bits.CREN = 1; } } return RCREG1; } Corrado Santoro Using the UART in PIC18F Family
  • 13. Using the UART in Microchip PIC18F Microcontrollers Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro Using the UART in PIC18F Family