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
vishwaditya.iyer
Associate II

yes,I checked with the mod bus master software and the meter is responding properly.

vishwaditya.iyer
Associate II

I checked and the MCU has a RTS/CTS interface should I use it. Also it has a special bit for half duplex transmission,I did not use it should I use it in this case.

I don't know your interface line handling, it seems not in the code you posted.

Check that the transfer direction is managed correctly, especially during reception.

Don't spend too much time in the receive interrupt. If you get an overflow, reception stops until you reset the flag manually.

Check for other UART errors in the interrupt handler.

My suggestion - clear the error flags, possibly marking the current response frame as invalid.

Receive the remaining bytes, and then drop it.

Repeat the request frame.

vishwaditya.iyer
Associate II

yes, because,my meter has only Tx/Rx lines it does not have a RTS/CTS flow control to connect to.

vishwaditya.iyer
Associate II

​Ok I will try to use RTS to control the enable pins,and try clearing overrun flag which was getting set

vishwaditya.iyer
Associate II

After clearing the overrun flag also it is only reading 1 byte. I was enabling the Receive enable inside the ISR , that was causing the overrun error. If I enable Receive pin inside main the error is solved but the receive buffer is reading the same packet which was transmitted.

This seems to depend on your hardware. If the Tx signal is feedback, you could safely ignore it (i.e. drop all received characters while you are sending).

I know that layout/hardware changes are usually difficult to press through, so you will probably settle with a SW workaround.

Not sure what the initial post means about DMA, but receive timing control (required for RTU) and DMA seems not the best choice to me.

vishwaditya.iyer
Associate II

should I transmit also through interrupt,instead of DMA.