SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette (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
 

Dernier

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

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