pont_mx
Joined: 16 May 2013 Posts: 1
|
Modbus Master does not receive messages from slave |
Posted: Fri May 24, 2013 9:06 am |
|
|
Hi everyone!
I'm implementing a Modbus RTU communication in a PIC18f4520, actually I'm using modbus CCS library. When i send a messge, the slave receive it, and does its work, but when the slave respond to the master, the master is not able to receive the massage.(for any function the exception always is TIMEOUT=12)
I didn't make any change on the library code
Code: | #include <main.h>
#include "LCD.c"
#define MODBUS_TIMER_USED MODBUS_TIMER_T1
#define MODBUS_PROTOCOL MODBUS_PROTOCOL_SERIAL
#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_ENABLE_PIN PIN_C5
#define MODBUS_SERIAL_RX_ENABLE PIN_C4
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SERAIL_RX_BUFFER_SIZE 64
#define MODBUS_TIMER_UPDATE MODBUS_TIMER_ISR
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#include <modbus.c>
#define MODBUS_SLAVE_ADDRESS 0x64
#use FAST_IO(D)
#use FAST_IO(A)
void main()
{
unsigned char flags = 0;
unsigned long int Frec = 290;
float FrecLCD;
setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
lcd_init();
modbus_init();
SET_TRIS_D(0x0F);
while(1)
{
//==================================================================
// read regieter 8451
if( ( (0x01&flags) == 0x00 ) && ( 0x01 == (0X01&INPUT_D()) ) )
{
delay_ms(8);
if((modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,8451,1)))
{
FrecLCD = (float)Frec/10;
printf(lcd_putc,"\fFrec: %2.1f \n", FrecLCD );
FrecLCD = (float)*(&modbus_rx.data[2]);
printf(lcd_putc,"%2.1f Hz Exep. %d", FrecLCD , modbus_rx.error);
}
else
{
printf(lcd_putc,"\fExep. %d", modbus_rx.error);
}
flags ^= 0x01;
}
if( ( (0x01&flags) == 0x01 ) && ( 0x00 == (0X01&INPUT_D())))
{
delay_ms(8);
//lcd_putc("\f =)");
flags ^= 0x01;
}
}
} |
I've been working on this for 3 days and i can't get it.
in advance thank you very much fory your help. |
|