Been busy with a Xmega to enable uart. While polling and ISR interface works fine (especially sending chars & strings from AVR to terminal), I am looking for a way to send strings from my terminal to the AVR.
At this moment I am capable in receiving single chars. In the ISR I see and be able to manipulate the receiving chars, however ever char is handled separately.
ISR( USART_RXC_vect ) // Note that this vector name is a define mapped to the correct interrupt vector { // See "board.h" USART_RXComplete( &USART_data ); }
So within this block every char is written to RXbuffer:
bool USART_RXComplete(USART_data_t * usart_data) { USART_Buffer_t * bufPtr; bool ans; bufPtr = &usart_data->buffer; /* Advance buffer head. */ uint8_t tempRX_Head = (bufPtr->RX_Head + 1) & USART_RX_BUFFER_MASK; /* Check for overflow. */ uint8_t tempRX_Tail = bufPtr->RX_Tail; uint8_t data = usart_data->usart->DATA; if (tempRX_Head == tempRX_Tail) { ans = false; }else{ ans = true; usart_data->buffer.RX[usart_data->buffer.RX_Head] = data; usart_data->buffer.RX_Head = tempRX_Head; } return ans; }
However I am looking for a way to get a string back from the buffer. Might be that I do understand the buffer part wrong.
I have seen the solutions to get the string based on the direct usart.data and put the string together based on next char till the "\n" is found and then the string is 0 terminated.
This can be put in the routine:
ISR( USART_RXC_vect )
However then I do not use the buffer... Any ideas on what I am missing.
Btw my starting point was/is AVR1522 for XMEGA. My goal is in the end to be able to implement the DMAC version.
Furthermore at this moment I do not need to receive any strings because I have no application for it. For a different project I am looking at RS485 implementation. And then I would like to be able to exchange info between a sensor array and a control interface.
Are there any best practices for serial communications?