SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Microcontroller Lab.
Eng.Khaled Tamziz
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 1
PPU IUT Cachan
Mechanical Department
Mechatronic
Asynchronous serial communication
Bibliography
microcontroller PIC 4550 documentation (PDF file)
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 2
PPU IUT Cachan
microcontroller PIC 4550 documentation (PDF file)
MPLAB_C18 librairies documentation (PDF files)
MPLAB_C18 header file xxx.h
MPLAB_C18 c file sources (mccsrcxxx)
Introduction
UART TX (PORTC RC7)
RX (PORTC RC6)
Transmission line (0/5V)
Reception line (0/5V)
TXREG
RXREG
TRMT bit
TRMT bit = 1 if transmission buffer is empty
RCIF bit
microcontroller
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 3
SPBRG = 8 or 16 bits Baud Rate
8 bits TX configration
8 bits Rx configuration
TRMT bit = 1 if transmission buffer is empty
TRMT bit = 0 if transmission buffer is full
RCIF bit = 1 if reception buffer is full
RCIF bit = 0 if reception buffer is empty
In the documentation : EUSART
Connexion with a PC through a RS232 serial link
USART TX
TXREG
RXREG
microcontroller
max 232
Port COM
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 4
RX
0/5 Volt +12/-12 Volt
In this configuration, we may use the PC as a supervisor
Transmission of one byte
1
2
3
TCLK
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 5
byte of 8 or 9 bits (to add a possible parity bit)
2
3
baud rate = 1/TCLK = FOSC / 16 / (SPBRG + 1) or FOSC/ 64 / (SPBRG + 1)
for us FOSC = 48 MHz
each transmitted byte is framed by a start bit and a stop bit
Possible transmission flow chart
configure USART
write the byte in TXREG
transmission buffer empty ?
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 6
write the byte in TXREG
another transmission ?
close USART
Transmission in C language using the microchip library
char text_emission[20]= " HELLO WORLDn " , u ;
unsigned int spbrg;
spbrg = 77 ; //48000000/(64*9600) -1 9600 bauds
OpenUSART
(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,spbrg);
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 7
header file : usart.h
for(i=0;text_emission[i] != 0;i++) // character by character
{
}
CloseUSART();
while(BusyUSART()==1); // wait for buffer empty
u = text_emission[i];
putcUSART(u); // transmission
Let’s go back to the OpenUSART function
OpenUSART
(
USART_TX_INT_OFF
&
USART_RX_INT_OFF
&
USART_ASYNCH_MODE
// interrupts transmission and reception OFF
// asynchronous mode (possibly synchronous)
spbrg = 77 ; //48000000/(64*9600) -1 9600 bauds
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 8
USART_ASYNCH_MODE
&
USART_EIGHT_BIT
&
USART_CONT_RX
&
USART_BRGH_LOW,
spbrg
);
// asynchronous mode (possibly synchronous)
// 8 bits word (possibly 9 bits)
// continous reception (possibly single)
// low speed (:64) (possibly high :16)
// baud rate = FOSC / 64 / (spbrg + 1)
Prototype : OpenUSART(char config , unsigned int spbrg);
Reception of one byte (without interrupt)
1 2
3
TCLK
bit 4 bit 5 bit 6 bit 6bit 2 bit 3bit 0 bit 1 stopstart
reception line
RCF bit
(buffer full)
4 RCIF bit is cleared when the RECREG is read
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 9
for us FOSC = 48 MHz
baud rate = 1/TCLK = FOSC / 16 / (SPBRG + 1) or FOSC/ 64 / (SPBRG + 1)
each byte (8 or 9 bits) is framed by a start bit and a stop bit
to error bits may be read after reception : FERR (Format) and OERR (Overrun)
Possible reception flow chart
configure USART
reception buffer empty ?
read the byte in RXREG
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 10
read the byte in RXREG
another reception ?
close USART
here, it’s possible to test
FERR and OERR
Reception in C language (without interrupt) using the microchip library
header file : usart.hchar reception ;
unsigned int spbrg;
spbrg = 77 ; // 48000000/(64*9600) -1 9600 bauds
OpenUSART
(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,spbrg);
for(i=0;i<10;i++) // expecting 10 characters
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 11
for(i=0;i<10;i++) // expecting 10 characters
{
}
CloseUSART();
while(!DataRdyUSART()); //waiting for buffer full
reception = ReadUSART();
//reading the character in the reception buffer
// here we could add the test of FERR and OERR
lcd_putc(reception); //this character is sent to the LCD display
Workshops
1st exercise : Send a message from the microcontroller to the PC
3rd exercise : State machine : supervise the robot with the hyperterminal :
d : the right wheel turns forward D : the right wheel turns backward
l : the right wheel turns forward L : the right wheel turns backward
spacebar : the wheel stops p : displays the value of th potentiometer
1 : displays the value of the right exterior optical sensor
2 : displays the value of the right interior optical sensor
2nd exercice : Send a message from the PC to the LCD display
Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 12
Connect the asynchronous port of the microcontroller to the PORT COM
of the PC
Run HyperTerminal, configure it at 9600 bauds, 8 bits, no parity, disconnect
(telephone icon)
Write, build, program the microcontroller and run your program
Open the Hyperterminal connection (telephone icon)
2 : displays the value of the right interior optical sensor
3 : displays the value of the left exterior optical sensor
4 : displays the value of the left interior optical sensor

Más contenido relacionado

Destacado (8)

Hydrolic Fluid purpose & properties (chapter 2)
Hydrolic Fluid purpose & properties (chapter 2)Hydrolic Fluid purpose & properties (chapter 2)
Hydrolic Fluid purpose & properties (chapter 2)
 
Timers
TimersTimers
Timers
 
Single phase im-lecture_10_1
Single phase im-lecture_10_1Single phase im-lecture_10_1
Single phase im-lecture_10_1
 
USART
USARTUSART
USART
 
IGCSE ICT
IGCSE ICTIGCSE ICT
IGCSE ICT
 
Hydraulic pumps performance and Characteristics
Hydraulic pumps performance and CharacteristicsHydraulic pumps performance and Characteristics
Hydraulic pumps performance and Characteristics
 
VEHICLE ROLLOVER ANALYSIS
VEHICLE ROLLOVER ANALYSISVEHICLE ROLLOVER ANALYSIS
VEHICLE ROLLOVER ANALYSIS
 
Sensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
Sensors, Proximity sensors. Optical – Through-beam, Optical - DiffuseSensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
Sensors, Proximity sensors. Optical – Through-beam, Optical - Diffuse
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Lecture 3b usart Asynchronous serial communication

  • 1. Microcontroller Lab. Eng.Khaled Tamziz Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 1 PPU IUT Cachan Mechanical Department Mechatronic
  • 2. Asynchronous serial communication Bibliography microcontroller PIC 4550 documentation (PDF file) Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 2 PPU IUT Cachan microcontroller PIC 4550 documentation (PDF file) MPLAB_C18 librairies documentation (PDF files) MPLAB_C18 header file xxx.h MPLAB_C18 c file sources (mccsrcxxx)
  • 3. Introduction UART TX (PORTC RC7) RX (PORTC RC6) Transmission line (0/5V) Reception line (0/5V) TXREG RXREG TRMT bit TRMT bit = 1 if transmission buffer is empty RCIF bit microcontroller Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 3 SPBRG = 8 or 16 bits Baud Rate 8 bits TX configration 8 bits Rx configuration TRMT bit = 1 if transmission buffer is empty TRMT bit = 0 if transmission buffer is full RCIF bit = 1 if reception buffer is full RCIF bit = 0 if reception buffer is empty In the documentation : EUSART
  • 4. Connexion with a PC through a RS232 serial link USART TX TXREG RXREG microcontroller max 232 Port COM Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 4 RX 0/5 Volt +12/-12 Volt In this configuration, we may use the PC as a supervisor
  • 5. Transmission of one byte 1 2 3 TCLK Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 5 byte of 8 or 9 bits (to add a possible parity bit) 2 3 baud rate = 1/TCLK = FOSC / 16 / (SPBRG + 1) or FOSC/ 64 / (SPBRG + 1) for us FOSC = 48 MHz each transmitted byte is framed by a start bit and a stop bit
  • 6. Possible transmission flow chart configure USART write the byte in TXREG transmission buffer empty ? Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 6 write the byte in TXREG another transmission ? close USART
  • 7. Transmission in C language using the microchip library char text_emission[20]= " HELLO WORLDn " , u ; unsigned int spbrg; spbrg = 77 ; //48000000/(64*9600) -1 9600 bauds OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,spbrg); Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 7 header file : usart.h for(i=0;text_emission[i] != 0;i++) // character by character { } CloseUSART(); while(BusyUSART()==1); // wait for buffer empty u = text_emission[i]; putcUSART(u); // transmission
  • 8. Let’s go back to the OpenUSART function OpenUSART ( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE // interrupts transmission and reception OFF // asynchronous mode (possibly synchronous) spbrg = 77 ; //48000000/(64*9600) -1 9600 bauds Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 8 USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, spbrg ); // asynchronous mode (possibly synchronous) // 8 bits word (possibly 9 bits) // continous reception (possibly single) // low speed (:64) (possibly high :16) // baud rate = FOSC / 64 / (spbrg + 1) Prototype : OpenUSART(char config , unsigned int spbrg);
  • 9. Reception of one byte (without interrupt) 1 2 3 TCLK bit 4 bit 5 bit 6 bit 6bit 2 bit 3bit 0 bit 1 stopstart reception line RCF bit (buffer full) 4 RCIF bit is cleared when the RECREG is read Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 9 for us FOSC = 48 MHz baud rate = 1/TCLK = FOSC / 16 / (SPBRG + 1) or FOSC/ 64 / (SPBRG + 1) each byte (8 or 9 bits) is framed by a start bit and a stop bit to error bits may be read after reception : FERR (Format) and OERR (Overrun)
  • 10. Possible reception flow chart configure USART reception buffer empty ? read the byte in RXREG Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 10 read the byte in RXREG another reception ? close USART here, it’s possible to test FERR and OERR
  • 11. Reception in C language (without interrupt) using the microchip library header file : usart.hchar reception ; unsigned int spbrg; spbrg = 77 ; // 48000000/(64*9600) -1 9600 bauds OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,spbrg); for(i=0;i<10;i++) // expecting 10 characters Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 11 for(i=0;i<10;i++) // expecting 10 characters { } CloseUSART(); while(!DataRdyUSART()); //waiting for buffer full reception = ReadUSART(); //reading the character in the reception buffer // here we could add the test of FERR and OERR lcd_putc(reception); //this character is sent to the LCD display
  • 12. Workshops 1st exercise : Send a message from the microcontroller to the PC 3rd exercise : State machine : supervise the robot with the hyperterminal : d : the right wheel turns forward D : the right wheel turns backward l : the right wheel turns forward L : the right wheel turns backward spacebar : the wheel stops p : displays the value of th potentiometer 1 : displays the value of the right exterior optical sensor 2 : displays the value of the right interior optical sensor 2nd exercice : Send a message from the PC to the LCD display Project Pedagogy approach of Microcontroller – Palestinian Robotic Cup 12 Connect the asynchronous port of the microcontroller to the PORT COM of the PC Run HyperTerminal, configure it at 9600 bauds, 8 bits, no parity, disconnect (telephone icon) Write, build, program the microcontroller and run your program Open the Hyperterminal connection (telephone icon) 2 : displays the value of the right interior optical sensor 3 : displays the value of the left exterior optical sensor 4 : displays the value of the left interior optical sensor