diff --git a/avclandrv.h b/avclandrv.h index d46ca89..ffc57f9 100644 --- a/avclandrv.h +++ b/avclandrv.h @@ -33,8 +33,8 @@ //------------------------------------------------------------------------------ #include "GlobalDef.h" -#define STOPEvent cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(UCSR0B, RXCIE0); -#define STARTEvent sbi(RTC.PITINTCTRL, RTC_PI_bp); sbi(UCSR0B, RXCIE0); +#define STOPEvent cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(USART0.CTRLA, USART_RXCIE_bp); +#define STARTEvent sbi(RTC.PITINTCTRL, RTC_PI_bp); sbi(USART0.CTRLA, USART_RXCIE_bp); #define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message(); diff --git a/com232.c b/com232.c index 4b1bfae..da87eb2 100644 --- a/com232.c +++ b/com232.c @@ -35,34 +35,28 @@ byte readkey; //------------------------------------------------------------------------------ void RS232_Init(void) { - // init LED - sbi(DDRB, 5); - cbi(PORTB, 5); +// // init LED +// sbi(DDRB, 5); +// cbi(PORTB, 5); RS232_RxCharBegin = RS232_RxCharEnd = 0; - UCSR0A = 0; - UCSR0B = ((1< 9600 - // 51 => 19200 - // 25 => 38400 - // 8 => 115200 - // 3 => 250000 - + USART0.CTRLA = USART_RXCIE_bm; // Enable receive interrupts + USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm | USART_RXMODE_NORMAL_gc; // Enable Rx/Tx and set receive mode normal + USART0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc | USART_SBMODE_1BIT_gc; // Async UART with 8N1 config + USART0.BAUD = 256; // 250k baud rate (64*F_CPU/(16*250k)) for F_CPU = 16MHz } //------------------------------------------------------------------------------ -ISR(USART_RX_vect) +ISR(USART0_RXC_vect) { - RS232_RxCharBuffer[RS232_RxCharEnd] = UDR0; // Store received character to the End of Buffer + RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received character to the End of Buffer RS232_RxCharEnd++; } //------------------------------------------------------------------------------ void RS232_SendByte(byte Data) { - while ((UCSR0A & _BV(UDRE0)) != _BV(UDRE0)); // wait for UART to become available - UDR0 = Data; // send character + loop_until_bit_is_set(USART0_STATUS, USART_DREIF_bp); // wait for UART to become available + USART0_TXDATAL = Data; // send character } //------------------------------------------------------------------------------ void RS232_Print_P(const char * str_addr) diff --git a/sniffer.c b/sniffer.c index f8d8627..bb85053 100644 --- a/sniffer.c +++ b/sniffer.c @@ -95,12 +95,12 @@ int main() // Key handler if (RS232_RxCharEnd) { - cbi(UCSR0B, RXCIE0); // disable RX complete interrupt + cbi(USART0.CTRLA, USART_RXCIE_bp); // disable RX complete interrupt readkey = RS232_RxCharBuffer[RS232_RxCharBegin];// read begin of received Buffer RS232_RxCharBegin++; if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty RS232_RxCharBegin = RS232_RxCharEnd = 0; // do reset Buffer - sbi(UCSR0B, RXCIE0); // enable RX complete interrupt + sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt switch (readkey) { case 'S': showLog = 0; RS232_Print_P(PSTR("READ SEQUENCE > \n"));