开发者

Atxmega USART flow control

I'm having some troubles with USART flow control on the Atxmega256. I'm communicating with a modem which uses RTS/CTS for flow control. Once the modem sets CTS to low, I want to stop sending data until it goes high again. I'm currently using interrupt driven USART routines and can't seem to find a good w开发者_如何学编程ay to halt the sending. If i just stop sending when CTS goes low, the data allready in the send buffers will still be sent and therefore lost.

I've tried the follow to disable/enable sending:

if(false == clearToSend()) {
  USART_TxdInterruptLevel_Set(data->usart, USART_TXCINTLVL_OFF_gc);
  while(false == clearToSend()) {}
  USART_TxdInterruptLevel_Set(data->usart, USART_TXCINTLVL_LO_gc);
}

Unfortunately that seems to disable the sending permanently. Any ideas?

Best regards Fredrik


Once the start bit is sent to the wire, you have to send the rest of the bits including the stop bit or else you will corrupt the data. It is not possible to stop sending data instantly when CTS is deactivated, and it is a common practise to allow for a few extra bytes before the sending is halted.

The XMEGA series does not have any deep USART FIFO, just the transmit shift register and a transmit holding register, so if your code stops writing to the USART as soon as the CTS is deactivated, you should be fine.


I had the same problem you described, albeit with an atxmega128a1. I implemented this only for the USART transmitter by using DMA transfers and monitor the RTS pin from the main loop. I know I have 32 bytes left in the FIFO of my USART<->USB interface when the RTS pin asserts.

When the pin asserts, I change the DMA trigger source (DMA.CH0.TRIGSRC) from DMA_CH_TRIGSRC_USARTC0_DRE_gc to DMA_CH_TRIGSRC_OFF_gc. This way the DMA is no longer triggered, and halts transmission. When the RTS pin gets low again I change the trigger source back to DMA_CH_TRIGSRC_USARTC0_DRE_gc.

This method requires polled monitoring of the RTS line and using DMA USART transfers. I'm using this with an FTDI FT232H running at 2MHz baudrate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜