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

Help with MODBUS SLAVE!

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



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

View user's profile Send private message Visit poster's website

Help with MODBUS SLAVE!
PostPosted: Wed Sep 04, 2013 2:28 pm     Reply with quote

Good afternoon!
For some time I have been trying to use the examples of Modbus that come with the CCS. The ex_modbus_master until it is working fine, however the ex_modbus_slave not work at all. The same board that put the routine to run Modbus Master that worked well put routine Modbus Slave to run, so I'm sure the hardware is working. I'm using the program Modbus Poll Master and Slave to communicate with the PC. I can not receive anything when working with pc in Master and Slave board on. I do not know what else to do.
Does anyone have any tips to give, or any Modbus slave routine that works correctly.

Here's an excerpt from my routine:

Code:

#include <MODBUS_SLAVE.h>
#define MODBUS_BUS SERIAL
#define MODBUS_TYPE MODBUS_TYPE_SLAVE
#define MODBUS_SERIAL_TYPE MODBUS_RTU
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define MODBUS_SERIAL_ENABLE_PIN PIN_C4
#define MODBUS_ADDRESS 0x05
#include "modbus.c"

   
int8 swap_bits(int8 c)
{
   return ((c&1)?128:0)|((c&2)?64:0)|((c&4)?32:0)|((c&8)?16:0)|((c&16)?8:0)
          |((c&32)?4:0)|((c&64)?2:0)|((c&128)?1:0);
}

void main()
{
   int8 coils = 0b00000101;
   int8 inputs = 0b00001001;
   int16 hold_regs[] = {0x8800,0x7700,0x6600,0x5500,0x4400,0x3300,0x2200,0x1100};
   int16 input_regs[] = {0x1100,0x2200,0x3300,0x4400,0x5500,0x6600,0x7700,0x8800};
   int16 event_count = 0;
.
.
.
.
.
.
.
.
// The same of example.......

Thank you very much.
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 05, 2013 2:24 pm     Reply with quote

Good afternoon.

What I could see in the routine of Slave she lock in "while (! Modbus_kbhit ());" Don`t go out of this condition. Sending data however, gets nothing. If this part of the routine remove, the PIC transmits various random data.
This infinite loop is causing no data reception.

Really I need a help in this routine Slave.

Thank you, Hugo.
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