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

using ex_modbus_slave.c
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

using ex_modbus_slave.c
PostPosted: Sun Apr 27, 2008 10:57 pm     Reply with quote

I am trying to implement a modbus type comms between a PIC and a PC program that communicate using modbus. I have been staring at the examples all day but still am not sure how to setup so i can use pins on the micro as inputs or outputs with respect to the modbus. I need on/off and analog inputs and on/off outputs.

any help appreciated
Yalis
Guest







Using Modbus example
PostPosted: Sat May 03, 2008 11:17 am     Reply with quote

Make sure you read the modbus protocol specifications
Get a 'free' modbus client like modbus poll
Check bitrate and modbus Address #define MODBUS_ADDRESS 123
Get communication going between modbus-poll and your PIC.

Below you will see the PIC data that is send to the modbus client.

Simply use these variable to send you own data .

Code:
 int8 coils = 0b00000101;
   int8 inputs = 0b00001001;
   int16 hold_regs[] = {0x8800,0x7700,0x6600,   SNIP
   int16 input_regs[] = {0x1100,0x2200,0x3300,0x4400, SNIP


Note the bug in ex_modbus_slave.c
Code:
if(modbus_rx.func == FUNC_READ_COILS)
//Bugfix             modbus_read_discrete_input_rsp(MODBUS_ADDRESS, 0x01, &data);
                     modbus_read_coils_rsp(MODBUS_ADDRESS, 0x01, &data);
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Sat May 03, 2008 1:55 pm     Reply with quote

thanks yalis

have had a look at the specs and sort of understood them but was unsure how to set them on the pic.

is all i have to do is have an if (input(pin_a1) set inputs = something if i want to have an input button? what if i want more than 8 inouts or outputs?

is the input regs for storing adc values and the likes? and the hold regs for recieving 16bit values?

once again thanks for the help
magnoedu
Guest







about modbus example
PostPosted: Wed May 27, 2009 8:21 pm     Reply with quote

I got my pc communicate with the Modbus slave example under rs232, I reply with ok, but I can not turn-on an output (function 5), read the condition of an input (function 2), read an analog input (function 4) and send a value for PWM (function 6) and etc. I think you have to assign a pin to a register is that?
please help-me

+++++++++++++++++++
Do not make duplicate posts to five threads.

See forum rule #8:
8. No spamming

Four posts deleted.
-- Forum Moderator
+++++++++++++++++++
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu May 28, 2009 1:41 am     Reply with quote

Quote:
I think you have to assign a pin to a register is that?

Quite right. The example code doesn't interface real inputs and outputs.

Obviously, it has been written under the assumption, that you are familar with the basic operation of a microprocessor and can supplement the missing link easily.

Somethink like calling the below code in the main loop:
Code:
inputs = input_a():
output_b(coils);
magnoedu



Joined: 29 May 2009
Posts: 11

View user's profile Send private message MSN Messenger

sorry
PostPosted: Fri May 29, 2009 3:15 pm     Reply with quote

I'm newbie.
But I sure do not have to use a register of the type
Code:

leds =coils;
portb =leds;
trisb(0);

besides
Code:
#use fast_io (b)
#byte portb=8

Please help me I'm getting nowhere.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri May 29, 2009 4:09 pm     Reply with quote

Code:
#byte portb=8

Unfortunately I'm not aware of a PIC device, for that this assignment would be valid. Where did you get it?
magnoedu



Joined: 29 May 2009
Posts: 11

View user's profile Send private message MSN Messenger

donĀ“t give up to me help-me please
PostPosted: Fri May 29, 2009 9:12 pm     Reply with quote

I am studying very hard to try to learn, but I live here in Brazil. Things are difficult so everyone thinks about money and not help. I'm driving in what I think on the internet.
I put your code but it just did this
Code:
int8 coils = 0b00000101;

lighting LEDs that are on the respective pins rb_2, example rb_0 and even if I send the command 5 to turn them off, there is no response to command.
please help me
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat May 30, 2009 3:15 am     Reply with quote

I understand, that your LEDs are reflecting the initialized value of the coils variable but can't be changed through MODBUS. If so, you apparently managed to connect the LEDs to the variable successful, but the MODBUS write to coils seems not work. Then there wouldn't be a problem of connecting to outputs rather than general MODBUS slave operation.
magnoedu



Joined: 29 May 2009
Posts: 11

View user's profile Send private message MSN Messenger

modbus is work fine
PostPosted: Sat May 30, 2009 10:04 am     Reply with quote

no communication is ok and so learn how to connect the Modbus and pin.
I am sending a command modbus response correct communication
speaks in code set for the bit of the port.
Code:

else
{
  // coils are stored msb->lsb so we must use 7-address
  if(modbus_rx.data[2] == 0xFF)
     bit_set(coils, 7-modbus_rx.data[1]);
  else
     bit_clear(coils, 7-modbus_rx.data[1]);

The code says to set bit 7, or set bit number with charged in modbus_rx.data[1]
magnoedu



Joined: 29 May 2009
Posts: 11

View user's profile Send private message MSN Messenger

I put the instructions
PostPosted: Wed Jun 03, 2009 11:59 am     Reply with quote

I put the instructions in the code
Code:
 while(TRUE)
   {         
     inputs = input_a();
     output_b(coils);

Now I have control for this pins in port_b but have no control for inputs.
Please help me.
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

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

PostPosted: Mon Sep 09, 2013 7:47 am     Reply with quote

I'm using Modbus slave routine example for testing, but it does not work. I'm using the PC Modbus Poll. The PC transmits and not get anything back. The PC program only sends and PIC returns nothing.
Would have any suggestions to make this example work?
Actually I need to send 2 analog channels for a device master. Getting run the sample program already help.

Thank you all.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 8:06 am     Reply with quote

I'd say the most likely problem is with the RS485 control.

Try some simple 'non modbus' tests, using the same hardware. Can the PC send data to the PIC?. Can the PIC send data to the PC?. What does each receive when nothing is sending?. Get the comm's working, before trying to use the example. It does work (or it did several months ago, when I last tried it....).

Best Wishes
hugo_br



Joined: 01 Aug 2011
Posts: 26
Location: BRAZIL

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

PostPosted: Mon Sep 09, 2013 8:27 am     Reply with quote

Good morning Ttelmah

I did a routine with the same hardware running as Master. And when sending commands it returns normally. I used the slave Modbus Poll to see if the data was coming and everything is normal.

I do not understand why when I record the slave routine does not work anything.

I do not know what else to do, I've done everything and nothing .....

I really need help.

Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 8:48 am     Reply with quote

What compiler version are you on?.

Best Wishes
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 1, 2  Next
Page 1 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