CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modbus timeout problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

Modbus timeout problem
PostPosted: Thu Apr 26, 2012 1:38 am     Reply with quote

Hi,
I am using modbus routine (as a master) for receiving data.
I am having a problem with timeout. In initialization I set timeout 10000.
According to the driver file this time is in uS. Therefore it means 10000 is equal to 10mS.
Whenever there is communication error (or modbus cable is not connected), after every 10mS timeout error will be generated.
But in my case it is not happening. Timeout error generates after 60mS instead of 10mS.
Why this is happening so?

I am using pic16f628A with 20MHz crystal.
My compiler version is 4.093

Here is my code
Code:

#include <16f628A.h>
#fuses HS,NOWDT,NOLVP,NOBROWNOUT,PUT
#use delay(clock=20M)

#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SERIAL_TIMEOUT 10000 //timeoout in us
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define MODBUS_SERIAL_ENABLE_PIN PIN_B0

#include "modbus.c"
#define MODBUS_SLAVE_ADDRESS 0x08

int m_hold_array[5];
int i;

void main()
{
   modbus_init();
   delay_ms(10);
   
   while(1)
   {
      output_toggle(PIN_A1);
      if(!(modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,1029,1)))
      {
         for(i=0;i<(modbus_rx.len);++i)
         {
            m_hold_array[i]=modbus_rx.data[i];
         }
      }
   }
}

Modbus file is too long, thats why I am not pasting it here. But if it is required then I will paste it here.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 5:47 am     Reply with quote

I didn't yet use the MODBUS master, but after I brief view to the code, I guess, the problem is caused by the silly timeout implementation.

It's counting 10000 delay_us(1) interlaced with polling kbdhit(). This can never work, not with a fast processor and less than ever with a slow PIC16. Simply adjust the MODBUS_SERIAL_TIMEOUT 10000 accordingly.
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 5:57 am     Reply with quote

Thanks for your reply FvM.
It means we have to set the timeout manually by setting the time and measure it with oscilloscope?

I also use 18f26k22 with 20Mhz and compiler version 4.124 but the same result.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group