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

Communicating with energy meter on MODBUS with P24FJ64GA004
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19587

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 1:57 am     Reply with quote

#define MODBUS_SERIAL_BAUD 9600

default baud on your device, is 19200....
hssn601



Joined: 31 Jan 2014
Posts: 20

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 7:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 7:53 am     Reply with quote

Yes what Ttelmah means it should be defined as 19200 and not 9600.

Regards
notbad



Joined: 10 Jan 2013
Posts: 68

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 8:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 8:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 24, 2014 8:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue May 06, 2014 5:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue May 06, 2014 7:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 07, 2014 1:01 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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