Reset the timer counter before the overflow in ATXMEGA64a1

atmegaportserialtimeruart

I want to reset the timer before the timer interrupt.

In my case, I will use the Mod bus protocol for serial port. I had to reset the timer for each byte sent and send data if the timer reach 3.5 ts(Time for sending byte). It mean if we didn't receive any byte until (3.5ts s ) we send data, if not, we add new data in the buffer.

So in this case, I want to use two interrupts:

  • One interrupt for the serial port Rx. In this interrupt I will reset the timer.
  • One interrupt for the Timer where I will send the Buffer.

Best Answer

Whenever you receive a byte, UART will generate an interrupt.In that ISR you can reset your timer to indicate that you have to wait for 3.5 bit time from now.

I never used this perticular controller, but to reset the timer, You can write 0 in it's timer/counter register OR there might a bit through which you can reset the timer. On checking datasheet, If you could set command to RESTART i.e. 10 in CTRLFSET register, it will restart the timer.

Everytime you recieve a byte, you will reset the timer and if no byte is recieved in 3.5 Bit time, Your timer interrupt will be generated and through that you can initiate the transmission!