Sensor data reading thr. UART

Showing results for 
Search instead for 
Did you mean: 

Sensor data reading thr. UART

Contributor III

Dear All,


Our environment are: CW10.2 / MQX3.8 / TWR-K60N512+TWR-SER. We are working on a project which should connect a sensor to the TWR-SER and read dara thr. RS485 interface.


Before the mqx software implementation, we consulted a hardware engineer to confirm the connection is working. Based on his suggestion(he confirmed the RS485 on TWR-SER is RS422, which is not compatible w. the RS485 on the sensor), we config theTWR-SER to RS232 and add a RS232-RS485 converter. The whole set passed the communication testing w. a PC.


Then we connect the sensor to TWR-SER(thr. the RS232-RS485 converter) and try to read the data. A 4-byte command should be sent to the sensor then a 12-byte data will be automatically replied. Unfortunately, below simple codes doesn't work, we don't get the correct data format in the rxbuff:


ret = _io_write(uart_dev, command, 4);
printf("_io_write ret = %d\n", ret);

ret = _io_read (uart_dev, rxbuff, 12);
printf("_io_read ret = %d\n", ret);
printf("rxbuff = %s\n", rxbuff);


However, we parallely connect the sensor to PC, the correct data can be read on a terminal, which means the write command through above code (execute in CW debug mode) is working but failed on read command. A friend comments we should read the buffer immediately after the write command, the read command is too late, but we don't know how it implement in mqx.


Any suggestion or comment is highly appreciated!



0 Kudos
1 Reply

Senior Contributor III

Hello tftu,


TWR-SER has RS485, there's ISL3176E (RS-485/RS-422 Transceivers) assembled on the board. It should be compatible with RS485. Anyway, that's not your problem.


What's your size of your buffer? Default value 64? How many characters does it read? Have you checked the internal ring buffer what characters are there? What is the return value of the _io_read? What serial mode is application using?




0 Kudos