Accessing UART (RS232/RS485) via FIFO

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Accessing UART (RS232/RS485) via FIFO

Post by xol »

Beginning from firmware version 0.2.0 SUB-20 supports connecting FIFO to UART (Universal Asynchronous Receiver Transmitter) for streaming RS232 communication. It is done with FIFO_SELECT_UART flag in call to sub_fifo_config.
Bytes written to FIFO with sub_fifo_write will be shifted out in RS232 frame format (start bit(s), data, optional parity, stop bit(s)) via RS232_PC_RX pin.
Bytes received via RS232_PC_TX pin will be stored in FIFO and could be read with sub_fifo_read.
UART should be configured with sub_rs_set_config.
Currently supported only RS232 model - SUB-20-R25. In next release we will add RS485 support for SUB-20-R45.

Example below shows sending 256 bytes in 9600 8N1 format and receiving 100 bytes back.

Code: Select all

sub_rs_set_config( hndl, RS_RX_ENABLE|RS_TX_ENABLE|RS_CHAR_8|RS_PARITY_NONE|RS_STOP_1, 9600 );
sub_fifo_config( hndl, FIFO_SELECT_UART );
sub_fifo_write( hndl, tx_buf, 256, 300 );
sub_fifo_read( hndl, rx_buf, 100, 1000 );
Special considerations should be done in calculating timeouts for FIFO read/write. FIFO size is 128 bytes. If for instance you write 60 bytes they can be stored in FIFO and 1ms timeout is enough for such operation. But for 130 bytes folowing will happen:
1. 128 bytes will be stored in FIFO
2. 64 bytes will be sent and first FIFO bank will be released
3. The remaining 2 bytes will be stored in released bank
So timeout should take in account sending 64 bytes at given baud rate.

Post Reply