AVR ATmega32 Mini Development Board – Serial Communication (USART)
The USART module of ATmega32 uses pins PD0 & PD1 for reception & transmission respectively. The mini development board can communicate with PC/external modules through
- USB port via CP2102
- Serial port via MAX232
- RMC connector K10 in 5V level
- RMC connector K16 in 3.3V level
Besides, USART is also used for interfacing Zigbee & RFID reader.
Note :
- USART communication via USB/serial port is selected using jumpers J1 & J2
- Short jumpers J13 & J14 while using 3V3 USART / Zigbee
- Remove jumpers J1 & J2 while using Zigbee / RFID/ UART (3V3/ 5V)
Schematic
Sample Code
The sample code to check USART module is given below. Initially the letter ‘A’ gets transmitted. Then, upon receiving a character, the same gets retransmitted.
Value in UBRR is calculated as follows
UBRR = (Fosc / (16 * BAUD)) – 1
The desired baudrate is 9600 bps and crystal frequency, Fosc is 8 MHz. This gives UBRR = 51. Any change in crystal frequency/baudrate changes this value as per the above equation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/************************************************************************************** HEADER FILE ***************************************************************************************/ #include<avr/io.h> /************************************************************************************** VARIABLE DECLARATION ***************************************************************************************/ volatile char Rec_Data; /************************************************************************************** MAIN FUNCTION ***************************************************************************************/ int main() { DDRD = 0X02; /* PD0(RX)-I/P, PD1(TX)-O/P */ UCSRA = 0X00; /* Clears TXC & RXC Flag Bit */ UCSRB = 0X18; /* Transmission & Reception Enable (TXEN=1, RXEN=1) */ UCSRC = 0X86; /* URSEL=1,UMSEL=0,UCSZ1=1,UCSZ0=0 */ UBRRL = 51; /* Serial Baudrate=9600 */ UDR = 'A'; /* Transmit a charcter */ while((UCSRA & 0X20)!=0X20); /* UDRE Flag Bit Check */ while(1) { while((UCSRA & 0X80)!=0X80); /* RXC is set when unread data is in receive buffer */ Rec_Data=UDR; /* Store the received character */ UDR = Rec_Data; /* Transmit the received character */ while((UCSRA & 0X20)!=0X20); /* Wait here till UDR is empty */ } } /************************************************************************************** END ***************************************************************************************/ |
OutputThe following screenshots explain how to test the sample code using RealTerm (click to download).
- Step 1: Open RealTerm
- Step 2: RealTerm opens as shown below
- Step 3: Go to ‘Port’ option, set correct baudrate (which is set as 9600 in the sample code) and correct port
- Step 4: Click ‘Change’ (encircled in red) to apply the changes. Now check the status of Port. If it is closed, click ‘Open’ button (encircled in green) to open it.
- Step 5: To check reception, go to Send option, type the string in the space provided(encircled in green) and click Send ASCII button. The first “hello” in green colour is transmitted from PC & that in yellow colour is retransmitted by the controller
Topics related to AVR ATmega32 Mini Development Board
- AVR ATmega32 Mini Development Board – Overview
- AVR ATmega32 Mini Development Board – Interfacing LED
- AVR ATmega32 Mini Development Board – Interfacing LCD
- AVR ATmega32 Mini Development Board – Serial communication(USART)
- AVR ATmega32 Mini Development Board – Interfacing Switch
- AVR ATmega32 Mini Development Board – Interfacing Buzzer
- AVR ATmega32 Mini Development Board – Interfacing POT(ADC)
- AVR ATmega32 Mini Development Board – Interfacing Temperature sensor
- AVR ATmega32 Mini Development Board – Interfacing Servo Motor
- AVR ATmega32 Mini Development Board – Interfacing μRFID
Resources
How to buy?
- Click here to buy rhydoLABZ AVR ATmega16 Development Board-Mini
- Click here to buy rhydoLABZ AVR ATmega32 Development Board-Mini
Support
Please share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.