snock
Joined: 10 Oct 2011 Posts: 24
|
CCS Modbus library hangups |
Posted: Mon Aug 05, 2013 6:51 am |
|
|
I am using the CCS modbus library from v1.124 and am experiencing a rare hang up. I have enabled the WDT on the part (PIC18F2680) but I am not sure that the micro itself is hanging. I have a red/green LED which indicates whether the unit is receiving or transmitting. I toggle the green side of it when something comes in. I notice that when the hangups occur that the green LED never gets toggled off so I am beginning to think that perhaps the unit only received a partial packet from the PC host and then hung up because the modbus_serial_new variable never got cleared. Here is the section of code that I think may be at fault:
Code: |
void incomming_modbus_serial() {
char c;
output_low(LED_GRN); // Turn on green side of Comm. LED
c=fgetc(MODBUS_SERIAL);
if (!modbus_serial_new)
{
if(modbus_serial_state == MODBUS_GETADDY)
{
modbus_serial_crc.d = 0xFFFF;
modbus_rx.address = c;
modbus_serial_state++;
modbus_rx.len = 0;
modbus_rx.error=0;
}
else if(modbus_serial_state == MODBUS_GETFUNC)
{
modbus_rx.func = c;
modbus_serial_state++;
}
else if(modbus_serial_state == MODBUS_GETDATA)
{
if (modbus_rx.len>=MODBUS_SERIAL_RX_BUFFER_SIZE) {modbus_rx.len=MODBUS_SERIAL_RX_BUFFER_SIZE-1;}
modbus_rx.data[modbus_rx.len]=c;
modbus_rx.len++;
}
modbus_calc_crc(c);
modbus_enable_timeout(TRUE);
output_high(LED_GRN); // Turn off green side of Comm. LED
}
}
|
If anyone has any pointers it would be much appreciated. BTW, I do have ERRORS set on the #use rs232 line. |
|