I have an FT 3120 unit which acts as a gateway between a Lon network and a PLC which it communicates with using SPI.
I'm having the issue that after some seemingly random time it stops transmitting to the Lon network. If I restart it by cutting the power supply it starts working again.
Previously it stopped very often (approximately once per 10 minutes on average) but I improved on this by letting the code check the device error status. If an error code is reported, the status is cleared and then the node is restarted by using the following code:
when(...)
...
status_struct status;
unsigned short logged_error;
retrieve_status(&status);
logged_error = status.status_error_log;
if (logged_error != 0)
{
node_status_to_plc_flag = TRUE;
}
...
}
when(node_status_to_plc_flag)
{
node_status_to_plc_flag = FALSE;
nodeStatusToPLC();
clear_status();
node_reset();
}
nodeStatusToPLC() reads the status again and transmits this over SPI to the PLC where I can monitor the data. One weird thing is that even though this is only triggered if logged_error != 0, most of the time the reported error that I see is 0. Sometimes I get the error 138 which is domain error, I find this to be a bit odd since I never change the domain.
To test the program, 3 messages are sent to the unit over SPI every 25 ms, these messages are 10 bytes each. The unit transmits these on the Lon network using unacklowedged, non-repeated messages with explicit messaging. Two nodes in the network then responds to one message each, these responses are also 10 bytes each (+ Lon network overhead). These responses are finally transmitted over SPI to the PLC. To sum it up the FT 3120 transmits 3 messages and receives 2 on the Lon network every 25 ms.
For the SPI communication the FT 3120 is master and the SPI bus runs at 20 kBaud. When the error occurs I know that the FT 3120 is still receiving the SPI messages since I don't get a buffer overflow on the PLC side.
Also, if I generate a message from one of the nodes it is passed on to the PLC.
Messages received from the SPI are first put in a buffer before they are sent on the Lon network with the following code:
priority when (data_ready_for_lon_tx == TRUE)
{
if ( msg_alloc() )
{
msg_out.service = UNACKD;
msg_out.tag = explicit_tag;
msg_out.code = (ConfigMode == 8?MASTER_CODE:SLAVE_CODE); // Check if unit is configured as Node or Gateway
memcpy(msg_out.data, &lon_tx_buff[lon_tx_buff_r_ptr], sizeof(event_msg));
//update buffer read pointer
lon_tx_buff_r_ptr++;
if (lon_tx_buff_r_ptr >= LON_TX_BUFF_SIZE)
lon_tx_buff_r_ptr = 0;
//check for empty buffer
if (lon_tx_buff_r_ptr == lon_tx_buff_w_ptr)
data_ready_for_lon_tx = FALSE;
msg_out.dest_addr = msg_dest_addr;
msg_send();
}
}
I'm running out of ideas to to test so I'm throwing it out here to see if anyone has any ideas about the cause of this.