00001
00051 #include "usart_driver.h"
00052 #include "avr_compiler.h"
00053
00055 #define NUM_BYTES 3
00056
00057 #define USART USARTC0
00058
00060 USART_data_t USART_data;
00062 uint8_t sendArray[NUM_BYTES] = {0x55, 0xaa, 0xf0};
00064 uint8_t receiveArray[NUM_BYTES];
00066 bool success;
00067
00068
00082 int main(void)
00083 {
00084
00085 uint8_t i;
00086
00087
00088
00089
00090 PORTC.DIRSET = PIN3_bm;
00091
00092 PORTC.DIRCLR = PIN2_bm;
00093
00094
00095 USART_InterruptDriver_Initialize(&USART_data, &USART, USART_DREINTLVL_LO_gc);
00096
00097
00098 USART_Format_Set(USART_data.usart, USART_CHSIZE_8BIT_gc,
00099 USART_PMODE_DISABLED_gc, false);
00100
00101
00102 USART_RxdInterruptLevel_Set(USART_data.usart, USART_RXCINTLVL_LO_gc);
00103
00104
00105
00106
00107
00108
00109
00110
00111 USART_Baudrate_Set(&USART, 12 , 0);
00112
00113
00114 USART_Rx_Enable(USART_data.usart);
00115 USART_Tx_Enable(USART_data.usart);
00116
00117
00118 PMIC.CTRL |= PMIC_LOLVLEX_bm;
00119
00120
00121 sei();
00122
00123
00124 i = 0;
00125 while (i < NUM_BYTES) {
00126 bool byteToBuffer;
00127 byteToBuffer = USART_TXBuffer_PutByte(&USART_data, sendArray[i]);
00128 if(byteToBuffer){
00129 i++;
00130 }
00131 }
00132
00133
00134 i = 0;
00135 while (i < NUM_BYTES) {
00136 if (USART_RXBufferData_Available(&USART_data)) {
00137 receiveArray[i] = USART_RXBuffer_GetByte(&USART_data);
00138 i++;
00139 }
00140 }
00141
00142
00143
00144 success = true;
00145 for(i = 0; i < NUM_BYTES; i++) {
00146
00147 if (receiveArray[i] != sendArray[i]) {
00148 success = false;
00149 }
00150 }
00151
00152
00153 if(success){
00154 while(true);
00155 }else{
00156 while(true);
00157 }
00158 }
00159
00160
00167 ISR(USARTC0_RXC_vect)
00168 {
00169 USART_RXComplete(&USART_data);
00170 }
00171
00172
00179 ISR(USARTC0_DRE_vect)
00180 {
00181 USART_DataRegEmpty(&USART_data);
00182 }