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 support@ccsinfo.com

Included Modbus Driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dtl



Joined: 16 Jan 2008
Posts: 5

View user's profile Send private message

Included Modbus Driver
PostPosted: Wed Jan 16, 2008 9:48 pm     Reply with quote

Hello,

I am new to the CCS compiler but not C in general. I do not claim to be a C expert though. I have gotten my standard serial comms working and am now trying to utilize the included Modbus driver to create a Modbus master. Here is an example program I used to send a Modbus command and by monitoring the port I see that the program is sending the correct stream, but my lack of full understanding of the driver has left me wondering how to receive the reply. I don't believe the called function is handling the slave response, if I am correct how do I get the reply?

Code:
#include <STD_SETTINGS.h>
#include <stdio.h>
#include <modbus.c>

void main()
{
modbus_read_input_registers(100, 0, 1);
}


I have searched the forums but I hope I haven't missed the answer to my question.

Thanks,
Dave
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Jan 16, 2008 11:02 pm     Reply with quote

I'm not familiar with modbus at all, but there is one thing that sticks out: your code is missing the infinite while() loop.

Structure your program like this:

Code:
main {
  // setups happen here
  while (TRUE) {
     // do your modbus tx & rx simple tests here, possibly separated by
     // delay_ms() statements
  } // end of while
} // end of main


Embedded programs are a little tough to wrap your head around at first. The program needs the while loop to cause the processor to keep from going to sleep. Each and every CCS program has a sleep instruction put at the end by the compiler. Your initial program is probably starting to attempt a modbus read, but before that can happen, the processor is going to sleep.
dtl



Joined: 16 Jan 2008
Posts: 5

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 9:12 am     Reply with quote

Thank you for that, I was not aware of the sleep instruction placed at the end of the program by the copiler.

My question really comes back to the fact that I am not a hundered percent sure where to even look for the reply. I know that I have called the correct function to transmit as I have monitered the port, I just need to know where to find the response or if another function needs to be called.

Thanks Again,
Dave
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 9:48 am     Reply with quote

You will need something like:

modval = modbus_read_input_registers(100, 0, 1);
dtl



Joined: 16 Jan 2008
Posts: 5

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 10:52 am     Reply with quote

It dosen't look to me like the "modbus_read_input_registers()" function returns the value the way you are describing. I could be misunderstasnding it though.

Dave
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 11:54 am     Reply with quote

You are right . Read_input_registers() function does not return nothing. This command enables the reading of the register in which the measurement is stored.
The function parameters should point to the Slave Address and the Number of the
Input register to be read. If the request was properly done, the targeted Slave should
respond accordingly.
To know the response, you should code to handle and store the Slave answer and show it,
just to test the node.


Humberto
dtl



Joined: 16 Jan 2008
Posts: 5

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 5:47 pm     Reply with quote

Humberto,

That is what I was thinking from reading the function in the driver file. Does anyone know what function in the driver handles the reply, including the CRC check? I would really like to use a funktion included in the driver rather than starting from scratch.

Thanks,
Dave
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 17, 2008 7:41 pm     Reply with quote

In the Code Library section of this forum, you will find an excelent interrupt driven data
streams with MODBUS packets posted by Neutone and others where you will see
how to construct an CRC generator/check, how is done the initialization procedure, how to
handle the received packets and how to use most of the included MODBUS functions.

http://www.ccsinfo.com/forum/viewtopic.php?t=19306



Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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