cancel
Showing results for 
Search instead for 
Did you mean: 

Communicating between STM32F4 and energy meter using mod bus-RTU.

vishwaditya.iyer
Associate II

we are trying to read the line voltage register in the energy meter(em6400ng) using mod bus RTU over RS-485 protocol. we are assembling the packet in an array and sending it to the energy meter using DMA. also we are receiving the packet in a buffer using interrupt. The energy meter is only sending the first byte that is slave id in response. we are not able to find out the reason this occurrence, please point out the problem in our code. The code is attached below.

17 REPLIES 17
Ozone
Lead

> we are trying ...

Who is "we" ... ?

To get an USART interrupt, you would need to configure and enable this interrupt somewhere.

I guess your reception stops at the second byte with an OV flag.

> The energy meter is only sending the first byte that is slave id in response.

Have you checked this with a scope, or is this an assumption ?

Modbus RTU is timing based.

I had written code for an implementation, too.

I did not start to evaluate receive package contents until the package was complete, i.e. the 3,5 character times had expired.

I checked it in watch window on debugger, also I tested my code with mod bus slave software with which my code is working fine.

A physical scope, at the physical Rx/Tx lines. Sometimes, assuming is not enough.

Ok, will check with the scope

Checking the whole sequence of devices/events in your scenario first is a good method to tackle a problem.

Assuming a commercial device (your energy meter Modbus slave) will respond with incorrect/corrupted messages out of the bow will not get you far.

I can see the whole packet length on the scope on Tx line, But can only see one byte on the scope for Rx line from the energy meter.

There is no valid RTU single-byte response.

Perhaps you have a half-duplex configuration, and grap the line after receiving the first byte ?

Like a RS-285 transceiver, using RTS to manage the transfer direction ?

vishwaditya.iyer
Associate II

I am using RS485 configuration, I am not using RTS to manage transfer, I am having a receive and transmit enable pin instead to manage transfer direction

> I am not using RTS to manage transfer, I am having a receive and transmit enable pin instead to manage transfer direction

And RTS of the MCU's UART interface is often used to control this receive/transmit enable pin of the transceiver.

However you control it, double-check it.

If you have any working RTU master, you can verify if your slave (metering device) works correctly. I bet it does.