View previous topic :: View next topic |
Author |
Message |
dtl
Joined: 16 Jan 2008 Posts: 5
|
Included Modbus Driver |
Posted: Wed Jan 16, 2008 9:48 pm |
|
|
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: 1909
|
|
Posted: Wed Jan 16, 2008 11:02 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 9:12 am |
|
|
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
|
|
Posted: Thu Jan 17, 2008 9:48 am |
|
|
You will need something like:
modval = modbus_read_input_registers(100, 0, 1); |
|
|
dtl
Joined: 16 Jan 2008 Posts: 5
|
|
Posted: Thu Jan 17, 2008 10:52 am |
|
|
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
|
|
Posted: Thu Jan 17, 2008 11:54 am |
|
|
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
|
|
Posted: Thu Jan 17, 2008 5:47 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 7:41 pm |
|
|
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 |
|
|
|