1
0
mirror of https://github.com/halleysfifthinc/Toyota-AVC-LAN synced 2025-06-07 16:06:12 +00:00

Update serial registers

This commit is contained in:
Allen Hill 2023-08-06 20:48:45 -04:00
parent feccda9e69
commit 66633db24e
3 changed files with 15 additions and 21 deletions

View File

@ -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();

View File

@ -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<<RXCIE0) | (1<<RXEN0) | (1<<TXEN0)); // enable RxD/TxD and interrupts
UCSR0C = ((1<<UCSZ01)|(1<<UCSZ00)); // 8N1
UBRR0L = 8; // Baud Rate 9600 (3 for 250000)
// 103 => 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)

View File

@ -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"));