cancel
Showing results for 
Search instead for 
Did you mean: 

STPM32 UART protocol details

DGiov.1
Associate III

Hello,

I'm working on a driver for a proprietary device that should interface with an STPM32 power meter via UART. I'm at the point of writing some routine to access STPM32 registers without the need of manually compose the UART frames.

However, I keep receiving garbage when I read register. I try to describe it below, but to make the long story short, the problem is that only the dummy read command properly works, when I try to read registers at specific position it mess up (I receive bad frames).

So, this is the test procedure:

After the initialization of GPIO and UART, I generate the pulses to properly reset the STPM32, then I do a trasfer to get the register at row 0 (address 0), moreover since I use the dummy read command on the next trasfer I'll get the register at row 1 (address 2)

MCU TX->STPM RX: (0x) FF FF FF FF 7B
MCU RX<-STPM TX: (0x) A0 00 00 04 75

then I receive the correct value with the correct CRC.

By doing another transfer I obtain the register at row 1 (address 2)

MCU TX->STPM RX: (0x) FF FF FF FF 7B
MCU RX<-STPM TX: (0x) A0 00 00 24 4D

and it is still correct. That's fine, uart and crc computation logic look properly working.

Now I want to read a register at a specific address, let's say I want to read again register at address 0, for this I use:

MCU TX->STPM RX: (0x) 00 FF FF FF F0
MCU RX<-STPM TX: (0x) C0 E0 04 00

during this transfer I expect to obtain register at address 0x04 but I obtain garbage (in fact there are only 4 bytes).

On the next transfer (regardless the command) I should receive again register 0 addressed in the previous transfer. Instead I obtain:

MCU TX->STPM RX: (0x) FF FF FF FF 7B
MCU RX<-STPM TX: (0x) E0 04 00 00 84

then I looks like the stpm is sending me the content of register at address 0x04.

Moreover, the two bytes of the frame containing the "DATA for 16-bit register to be written" (i.e. the bytes number 3 and 4 of the frame) should be ignored when using dummy write command. However, if I change those FF into something else the STPM goes crazy and send 6-7 bytes. In all the cases where it goes bad, the probed signals on the TX/RX lines are wierd (the oscilloscope doesn't manage to decode the UART data).

So, am I doing something wrong? Any suggestion?

Thank you,

Davide.

1 ACCEPTED SOLUTION

Accepted Solutions
DGiov.1
Associate III

Solved, I didn't realize the optocoupler was inverting the logic of the SYN pin, therefore the reset procedure was incomplete and the SYN was left to 0 (and not 1) during operation.

View solution in original post

4 REPLIES 4
DGiov.1
Associate III

Solved, I didn't realize the optocoupler was inverting the logic of the SYN pin, therefore the reset procedure was incomplete and the SYN was left to 0 (and not 1) during operation.

dbgarasiya
Senior II

good ,

Hi DGiov,

I am planning to implement the energy meter using STPM32. The communication is UART opto-isolation. I connected directly H11LS to STPM32 Tx/Rx. It require 1.6mA as sink. Is it support this current rating.

Thank you.

MZhoe.1
Associate

Hello

I am working on a driver for arduino and stpm 32 connection uart spi rs232 I checked through the STPM3x Evaluation program everything works Software but how can I read active energy through arduino? help please thank you