mirror of
				https://github.com/halleysfifthinc/Toyota-AVC-LAN
				synced 2025-10-31 10:27:24 +00:00 
			
		
		
		
	Update serial registers
This commit is contained in:
		
							parent
							
								
									feccda9e69
								
							
						
					
					
						commit
						66633db24e
					
				| @ -33,8 +33,8 @@ | |||||||
| //------------------------------------------------------------------------------
 | //------------------------------------------------------------------------------
 | ||||||
| #include "GlobalDef.h" | #include "GlobalDef.h" | ||||||
| 
 | 
 | ||||||
| #define STOPEvent  cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(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(UCSR0B, RXCIE0); | #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(); | #define CHECK_AVC_LINE		if (INPUT_IS_SET) AVCLan_Read_Message(); | ||||||
|  | |||||||
							
								
								
									
										28
									
								
								com232.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								com232.c
									
									
									
									
									
								
							| @ -35,34 +35,28 @@ byte readkey; | |||||||
| //------------------------------------------------------------------------------
 | //------------------------------------------------------------------------------
 | ||||||
| void RS232_Init(void) | void RS232_Init(void) | ||||||
| { | { | ||||||
|  // init LED
 | //  // init LED
 | ||||||
|  sbi(DDRB, 5); | //  sbi(DDRB, 5);
 | ||||||
|  cbi(PORTB, 5); | //  cbi(PORTB, 5);
 | ||||||
| 
 | 
 | ||||||
|  RS232_RxCharBegin = RS232_RxCharEnd = 0; |  RS232_RxCharBegin = RS232_RxCharEnd = 0; | ||||||
| 
 | 
 | ||||||
|  UCSR0A = 0; |     USART0.CTRLA = USART_RXCIE_bm; // Enable receive interrupts
 | ||||||
|  UCSR0B = ((1<<RXCIE0) | (1<<RXEN0) | (1<<TXEN0));	// enable RxD/TxD and interrupts
 |     USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm | USART_RXMODE_NORMAL_gc; // Enable Rx/Tx and set receive mode normal
 | ||||||
|  UCSR0C = ((1<<UCSZ01)|(1<<UCSZ00));				// 8N1
 |     USART0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc | USART_SBMODE_1BIT_gc; // Async UART with 8N1 config
 | ||||||
|  UBRR0L  = 8;   // Baud Rate 9600 (3 for 250000)
 |     USART0.BAUD = 256; // 250k baud rate (64*F_CPU/(16*250k)) for F_CPU = 16MHz
 | ||||||
|                 // 103  =>    9600
 |  | ||||||
|                 // 51   =>   19200
 |  | ||||||
|                 // 25   =>   38400
 |  | ||||||
|                 // 8    =>  115200
 |  | ||||||
|                 // 3    =>  250000
 |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
| //------------------------------------------------------------------------------
 | //------------------------------------------------------------------------------
 | ||||||
| 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++; |     RS232_RxCharEnd++; | ||||||
| } | } | ||||||
| //------------------------------------------------------------------------------
 | //------------------------------------------------------------------------------
 | ||||||
| void RS232_SendByte(byte Data) | void RS232_SendByte(byte Data) | ||||||
| { | { | ||||||
| 	while ((UCSR0A & _BV(UDRE0)) != _BV(UDRE0));	// wait for UART to become available
 |     loop_until_bit_is_set(USART0_STATUS, USART_DREIF_bp); // wait for UART to become available
 | ||||||
| 	UDR0 = Data;									// send character
 |     USART0_TXDATAL = Data; // send character
 | ||||||
| } | } | ||||||
| //------------------------------------------------------------------------------
 | //------------------------------------------------------------------------------
 | ||||||
| void RS232_Print_P(const char * str_addr) | void RS232_Print_P(const char * str_addr) | ||||||
|  | |||||||
| @ -95,12 +95,12 @@ int main() | |||||||
| 
 | 
 | ||||||
| 	// Key handler
 | 	// Key handler
 | ||||||
| 	if (RS232_RxCharEnd) { | 	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
 | 		readkey = RS232_RxCharBuffer[RS232_RxCharBegin];// read begin of received Buffer
 | ||||||
| 		RS232_RxCharBegin++; | 		RS232_RxCharBegin++; | ||||||
| 		if (RS232_RxCharBegin == RS232_RxCharEnd)		// if Buffer is empty
 | 		if (RS232_RxCharBegin == RS232_RxCharEnd)		// if Buffer is empty
 | ||||||
| 			RS232_RxCharBegin = RS232_RxCharEnd = 0;	// do reset Buffer
 | 			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) { | 		switch (readkey) { | ||||||
| 			case 'S':	showLog = 0; | 			case 'S':	showLog = 0; | ||||||
| 				RS232_Print_P(PSTR("READ SEQUENCE > \n")); | 				RS232_Print_P(PSTR("READ SEQUENCE > \n")); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user