Home/Support/Support Forum/RS485 in µC/OS-II
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

RS485 in µC/OS-II

0 votes
RS485 example in µC/OS-II? I'm use RCM5600w with DC 10.72
asked Jul 11, 2015 in Rabbit Software by edha Community Contributor (71 points)

Please log in or register to answer this question.

1 Answer

0 votes
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:

1. 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.

2. 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
}
answered Jul 12, 2015 by petermcs Veteran of the Digi Community (1,130 points)
...