Porting FreeMODBUS for the SCR1000 Control Board

Porting FreeMODBUS for the SCR1000 Control Board

Posted by Jon Young on Oct 28, 2010 10:43:00 AM

For our SCR1000 board, we needed to implement a Modbus stack for communicating with the board over RS-485. We have previously ported the FreeMODBUS stack to the Texas Instruments 28335 for use on the OZDSP3000 board, so again we selected FreeMODBUS for use on the Stellaris part that controls the SCR1000

The SCR1000 only requires the use of the RTU mode of Modbus, so the port should have been simple. However, the interrupts differ from that of the 28335, so I needed to make some simple modifications. For receive data, I had to modify the ISR handler to remove all of the data from the UART RX FIFO, instead of just a single byte:

if ( status & (UART_INT_RX | UART_INT_RT) )
{
  while ( MAP_UARTCHarsAvail (UART0_BASE))
    pxMBFrameCBByteReceived ();
   .....

That got the receives working in short order. Next up was sending a response. The TX interrupt sources are limited to different "full" levels of the TRX FIFO. The setup of the FreeMODBUS library assumes an empty interrupt. Luckily, we are using Rev C3 silicon of the Stellaris part, which provides access to the ETO - end of transmission interrupt. Enabling this interrupt, which disables the FIFO interrupts, and modifying eMBRTUSend() solved the problem:

/* Activate the transmitter */
eSndState = STATE_TX_XMIT;
vMBPortSerialEnable ( FALSE, TRUE );
pxMBFrameCBTransmiterEmpty ();  //This was added by Oztek

This will kick of the transfer of the first byte, and then the library is free to continue operating as expected. The EOT interrupt will call the ISR handler, which in turn calls pxMBFrameCBTransmitterEmpty() until all of the bytes have been sent.

We use the calls to vMBPortSerialEnable(,) to handle setting the direction of the enable bit for the RS485 transceiver on the SCR1000.

Topics: SCR, DSP