View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Apr 24, 2014 1:57 am |
|
|
#define MODBUS_SERIAL_BAUD 9600
default baud on your device, is 19200.... |
|
|
hssn601
Joined: 31 Jan 2014 Posts: 20
|
|
Posted: Thu Apr 24, 2014 7:47 am |
|
|
Ttelmah wrote: | #define MODBUS_SERIAL_BAUD 9600
default baud on your device, is 19200.... |
dear its already defined see system.h |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Thu Apr 24, 2014 7:53 am |
|
|
Yes what Ttelmah means it should be defined as 19200 and not 9600.
Regards |
|
|
notbad
Joined: 10 Jan 2013 Posts: 68
|
|
Posted: Thu Apr 24, 2014 8:11 am |
|
|
I'm not an expert but I suggest you test with a simple setup.
Let modbus library use hardware UART.
Use ASCII mode and if you can, use another 485 receiver and a PC to see whats going on the bus.
Check if communication parameters(baudrate etc.) are the same between PIC and slave.
Check power and wiring.
You can test one thing. Connect your PC to your unit using a USB<>485 converter and type modbus ASCII commands in a terminal program(like HyperTerminal) and see if it responds.
Make sure your terminal program is set to send both CR and LF. |
|
|
hssn601
Joined: 31 Jan 2014 Posts: 20
|
|
Posted: Thu Apr 24, 2014 8:19 am |
|
|
alan wrote: | Yes what Ttelmah means it should be defined as 19200 and not 9600.
Regards |
on energy meter i have changed it to 9600 |
|
|
hssn601
Joined: 31 Jan 2014 Posts: 20
|
|
Posted: Thu Apr 24, 2014 8:20 am |
|
|
notbad wrote: | I'm not an expert but I suggest you test with a simple setup.
Let modbus library use hardware UART.
Use ASCII mode and if you can, use another 485 receiver and a PC to see whats going on the bus.
Check if communication parameters(baudrate etc.) are the same between PIC and slave.
Check power and wiring.
You can test one thing. Connect your PC to your unit using a USB<>485 converter and type modbus ASCII commands in a terminal program(like HyperTerminal) and see if it responds.
Make sure your terminal program is set to send both CR and LF. |
hm i am also thinking off something like this. |
|
|
hssn601
Joined: 31 Jan 2014 Posts: 20
|
|
Posted: Tue May 06, 2014 5:49 am |
|
|
i only want to read values of some registers so i have written my own program.
the problem is that sometimes it stuck on fgetc() may be because nothing is comming from port .
i am using software serial.
Code: |
read4012(){
DIR_485_OUT();
InitializeModbus();
//sending command to read register
delay_ms(10);
for(int i=0; i<8 ; i++){
fprintf(S_SERIAL3,"%c",read4012c[i]);
fprintf(SERIAL2,"%c",read4012c[i]);
}
DIR_485_IN();
int sbuff[8];
//Reading Response
for(i=0 ; i<7; i++){
sbuff[i]=fgetc(S_SERIAL3); // here code gets sucked may be becauce nothing is comming.
}
//timeout=0;ready=0;
float result=make16(sbuff[3],sbuff[4]);
result = result/100;
fprintf(SERIAL2,"Frequency=%3.2f \r",result);
result=0;
}
InitializeModbus(){
DIR_485_OUT();
for(int i3=0;i3<10;i3++){
for(int i2=0; i2<8 ; i2++){
fprintf(S_SERIAL3,"%c",read4012c_ini[i2]);
//fprintf(SERIAL2,"%c",read4012c[i]);
}
}
}
|
sbuff[i]=fgetc(S_SERIAL3);
i just want to advance to next line if fgetc(S_SERIAL3); reads nothing for 10ms |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Tue May 06, 2014 7:24 am |
|
|
Look at the timeout option in #use rs232
There may well be better ways of handling things, but this is a start. |
|
|
hssn601
Joined: 31 Jan 2014 Posts: 20
|
|
Posted: Wed May 07, 2014 1:01 am |
|
|
Ttelmah wrote: | Look at the timeout option in #use rs232
There may well be better ways of handling things, but this is a start. |
thanks solved my problem. |
|
|
|