hugo_br
Joined: 01 Aug 2011 Posts: 26 Location: BRAZIL
|
Help with MODBUS SLAVE! |
Posted: Wed Sep 04, 2013 2:28 pm |
|
|
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
|
|
Posted: Thu Sep 05, 2013 2:24 pm |
|
|
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. |
|