# RCM 3900 modbus

**URL:** <https://forums.digi.com/t/rcm-3900-modbus/9037>\
**Category:** Rabbit\
**Created:** [April 26, 2011, 9:04am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037 "2011-04-26T09:04:58Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 28, 2011, 2:50pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/21 "2011-04-28T14:50:58Z")

</div>

When I run the program step by step … I do not go through the functions and MBM\_Send\_ADU MBM\_Rcv\_Resp …

More if I MBM\_ReadRegs i = (07, & RegsValue [0], 0xC55E, 2);  
and I print RegsValue [30], I -7012 … instead of 0 …

I really really do not see why not …

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 28, 2011, 2:54pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/22 "2011-04-28T14:54:11Z")

</div>

I have a question!  
The values ​​in the registers are double words … and my regValue [] is declared int … This can cause errors?

Thanks

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 28, 2011, 3:12pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/23 "2011-04-28T15:12:12Z")

</div>

The register size is normally 16bits but many devices use 2 successive registers to holde a 32 bit value. You have to interpret the data returned to convert it into the correct format (byte order etc may differ from the Rabbits so you need to know what the order is).

I’ve written test code very similar to yours and am debugging it at the moment. I get the TX: message and am not yet receiving any response but the RS485 adapter on my PC is seeing my request and the electricity meters response in my test setup so I am just going through the receive side of things now to see what is missing.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 28, 2011, 3:20pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/24 "2011-04-28T15:20:45Z")

</div>

Can you paste your program … Perhaps with your own I would find my mistake …

Thank you Peter

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 28, 2011, 3:37pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/25 "2011-04-28T15:37:36Z")

</div>

I’ll do so when I have it all working. Probably tomorrow as I have to finish up early today.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 28, 2011, 3:47pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/26 "2011-04-28T15:47:07Z")

</div>

Okay, thanks Peter 😃

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 29, 2011, 7:42am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/27 "2011-04-29T07:42:46Z")

</div>

Hey Peter, I have something new: D

I changed my slave for another plant. When I run my program, I have the same thing as you now …  
Tx: 05 03 10 00 00 02 4F C1

With the statement:  
main ()  
{int i;  
RegsValue double [50];  
serine ();  
MBM\_ReadRegs i = (005, & RegsValue [0], 0x1000, 2); / / read reg 0  
if (i == 0)  
printf ("Connect OK “);  
else printf (“Connection Not OK”);  
printf (”% d,% d \ n ", RegsValue [0], RegsValue [1]);  
while (1);  
}

We are not far to get there!

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 29, 2011, 10:55am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/28 "2011-04-29T10:55:39Z")

</div>

I got the transmit and receive working with the following:

/\*\*\* BeginHeader \*/  
// Normal MBUS debug printing  
#ifndef NRG\_MODBUS\_PRINT  
#define NRG\_MODBUS\_PRINT 0  
#endif

#ifdef NRG\_MODBUS\_DEBUG  
#define \_modbus\_dbg debug  
#else  
#define \_modbus\_dbg nodebug  
#endif

/\*\*\* EndHeader \*/

/\* START FUNCTION DESCRIPTION \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
MBM\_Send\_ADU

SYNTAX: int MBM\_Send\_ADU ( char \*Packet, int ByteCount );

DESCRIPTION: Transmit a Modbus packet to a “downstream” device.  
Calculate the CRC and append to the packet.  
There is a 50msec timeout hard coded in this function.

PARAMETER1: address of packet - must have two byte pad at end for  
inclusion of CRC word

PARAMETER2: number of bytes in the packet

RETURN VALUE: MB\_SUCCESS

Note: these functions do NOT implement the Modbus protocol delay of  
3.5 byte times.

END DESCRIPTION \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*\*\* BeginHeader MBM\_Send\_ADU _/  
int MBM\_Send\_ADU(char Packet, int ByteCount);  
/_\* EndHeader \*/  
\_modbus\_dbg  
int MBM\_Send\_ADU(char \*Packet, int ByteCount)  
{  
unsigned CRCvalue;  
unsigned long Endtime;  
int i;

// insert CRC  
CRCvalue = MODBUS\_CRC ( Packet, ByteCount );  
Packet[ByteCount+1] = CRCvalue; // store low byte  
Packet[ByteCount] = CRCvalue\>\>8; // store high byte  
ByteCount+=2; // adjust for CRC

#if NRG\_MODBUS\_PRINT  
printf(“Tx:”);  
for(i=0; i

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 29, 2011, 11:25am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/29 "2011-04-29T11:25:55Z")

</div>

Another thing to note is that this code does not support broadcast messages properly as it always looks for a response.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 29, 2011, 11:50am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/30 "2011-04-29T11:50:54Z")

</div>

Just did some quick tests and the timeout is definetly a problem in my case. I’m using a Femto D4 electricity meter for my tests and if I set the timeout to 50ms I don’t read the response, at 100ms I get the response about 75% of the time and at 150ms I always get the response.

Checking with a scope I see that the meter is responding between 80ms and 120ms after receiving the request. I don’t think it is exactly a speed demon!

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 29, 2011, 12:37pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/31 "2011-04-29T12:37:00Z")

</div>

It is good if it works for you. : D

But I do not understand, you do not define ser485Tx () and ser485Rx () in your program … and you have not used modbus\_master.lib!

Why?

Thank you

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 29, 2011, 1:48pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/32 "2011-04-29T13:48:10Z")

</div>

The test application itself has the #use modbus\_master.lib statement. I didn’t post this code as it is not that much different to yours.

The ser485TX/RX functions are supplied by the BLxS2xx.lib library. You don’t actually need these in your code or the brdinit function as they are in the RCM39xx.lib file. All you need to do is have #use bl39xx.lib at the top of your program and they should be linked in.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 29, 2011, 1:49pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/33 "2011-04-29T13:49:41Z")

</div>

When I run the program step by step, he stops at the following statement:  
while (serCrdUsed ()! = ByteCount);  
As if serCrdUsed () was always different from ByteCount …

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [April 29, 2011, 1:57pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/34 "2011-04-29T13:57:51Z")

</div>

Okok i want to test with bl39xx.lib but i dont have this in my file… where is it??

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 29, 2011, 2:31pm UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/35 "2011-04-29T14:31:23Z")

</div>

This should be in the samples\RCM3900 folder. The name is RCM39XX.LIB

Idea of using the serCrdUsed value is that when the RS485 lines are set correctly, each byte transmitted by the RCM3900 is also received by the controller because the RS485 tranceiver is wired up with a single enable which means the RX line is active when TX mode is selected.

This code uses the count of bytes received to see when all the data has been trensmitted. If your RS485 lines are not switching correctly then this will mean no data received back. Other things which can break this logic are shorts or execssive loading on the RS485 line, bad line bias and so on which stop the data from being received correctly.

The MS/TP code in the BACnet stack uses the serXsending function to determine when all the RS485 data has been transmitted and you might be able to port that function from the DC10.66 RS232.LIB to the DC9.62 RS232.LIB if you want a safe mechanism for determining the end of data transmission.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Termi](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Termi](https://forums.digi.com/u/Termi)\
**Post date:** [May 11, 2011, 9:15am UTC](https://forums.digi.com/t/rcm-3900-modbus/9037/36 "2011-05-11T09:15:27Z")

</div>

Hello,

How do I configure my BrdInit enabled RCM3900 for my RS485 ports?? (P c)  
I think my error comes from there?

Thank you all

[Previous page](https://forums.digi.com/t/rcm-3900-modbus/9037.md?page=1)
