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