Wednesday, May 28, 2014

Polling based USART

Using the example code from AVR1307 documentation.

In the master side, we continually check for the data register empty flag(DREIF) in a do-while loop.
DREIF = 1  >>> Transmit buffer is empty
DREIF = 0 >>> Transmit buffer contains data to be transmitted.

So, if the DREIF is not set, then the controller is stuck here. Seems like a major problem.
As soon as the DREIF is set, we place the new data to be sent into the data register. and this loops.

On the slave side, we have the timeout and the Receive complete interrupt flag(RXCIF).
RXCIF = 1 >>> unread data is there in the buffer.
RXCIF = 0 >>> data has been read and the buffer is empty.

Either wait for the timeout or for RXCIF to be cleared. then read whatever data present in the data register into your variable. If master screws up, will end up reading zeros into the receive variable.

My problem statement -
If i want to run DAC and polled USART both at the same time, it would cause problems, i suppose.
DAC conversion is based on timer overflow, event based conversion. this exists in the while(1) loop.

I would have to add the USART receive code also in the while loop, as i need to continually monitor the RXCIF flag. once i receive data, i have execute the receiving code for the number of bytes that are to be received. Time out would be needed during reception but not after.

Considering the transmitting controller, it has USB running. every 1 ms the controller is interrupted.
I think i need to figure out exactly how the program execution flows in the USB, so that i know which route the controller is taking and then to catch it between interrupts and send the data to be sent.

Work to be done on both transmitter and receiver side.
Its like whatever i have done for a year makes no sense now.
Crap.

No comments:

Post a Comment