RS485 example in µC/OS-II? I’m use RCM5600w with DC 10.72
The issues with uC/OSII and RS485 will vary depending on the protocol but using Modbus as an example there are two things that need to be aware of:
-
The inter byte gaps. Strictly speaking Modbus does not allow more than a certain delay between consecutive bytes in a packet so you need to ensure that you send all the data in one go.
-
Once the data has been sent, you need to disable the transmitter so that any response can be read - or if you are a slave so that the next master request can be sent.
Task switching can interfere with both of these but in particular the second. In my GET-1032 device I have the Modbus task running at a relatively low priority but when it is sending the data I temporarily switch to a higher priority so that the data can be sent correctly:
if(iMMSerialPort == NRG_MM_RS485_PORT)
{
ser485Tx(); // enable the RS485 transmitter
serXrdFlush(NRG_MBM_PORT); // clear the read FIFO
OSTaskChangePrio(NRG_TASK_PRI_IO, NRG_TASK_PRI_IO_HI); // Switch to higher priority to preserve sending timing
serXwrite(NRG_MBM_PORT, Packet, ByteCount); // send the data
while(serXsending(NRG_MBM_PORT))
; // wait for all bytes to be transmitted
ser485Rx(); // disable the RS485 transmitter
serXrdFlush(NRG_MBM_PORT); // clear the read FIFO
OSTaskChangePrio(NRG_TASK_PRI_IO_HI, NRG_TASK_PRI_IO); // Switch back lower priority
}
else
{
serXwrite(NRG_MBM_PORT, Packet, ByteCount); // send the data
serXrdFlush(NRG_MBM_PORT); // clear the read FIFO
}