SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch (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
 

Kürzlich hochgeladen

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Kürzlich hochgeladen (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

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