cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401 Interpreting DMA data over serial

gulagman145
Visitor

Hi all,

I am pretty new to ST so bear with me.

The controller is reading in voltage values into the ADC and sending to PC over serial with

CDC_Transmit_FS((uint8_t*), buffer, buffer_length)

I'm getting the data stream, but the values as read in python for instance are b'\x03', b'\x04' with every other value being b'\x03'.

I am trying to figure out how to 'decode' the data for lack of a better word. What format is the data being sent? I'm assuming since it is direct from memory it is bytes (binary)? The code is set up to trigger the transmit function when the ADC conversion is completed, and the parameters I give would indicate the value is in 8-bit bytes for the entire buffer, but I am stymied by the formatting on the receive end.

Some reading indicates that the values shown may either be ascii or something presenting in that way due to how python interprets the data but this has been very difficult for me to figure out since I know next to nothing about direct memory access or ST functionality. When viewing the data in a serial monitor it comes through as a bunch of strange characters different from what I have in python too, not much help there.

Any guidance would be greatly appreciated!

 

 

3 REPLIES 3
PGump.1
Senior III

Hi,

Perhaps, encoding your ADC reading into either a hexadecimal or decimal string with a Null between each reading.

I hope that helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.
Ozone
Lead II

I would agree to PGump.1, avoid binary.
Serial communication is prone to data corruption, and you proably don't want one missed or corrupted character to spoil an entire transmission.

Using ASCII (i.e. printf()) introduces redundancy, which allows you to detect a lot of data corruption. Binary does not, i.e. every byte values would be possible.
And using lines separated with '\n', '\0' (or both) helps in this regard as well.

> Some reading indicates that the values shown may either be ascii or something presenting in that way due to how python interprets the data  ...

Not to mention, you would come across the endianness problem sooner or later.
I'm not much into Python, but reading/parsing ASCII data from a serial line is identical to reading them from a file.
If you use Unix/Linux as host OS, you would realize both are treated as files, and use the same functions (at least in C code).

Hi,

"Serial communication is prone to data corruption" I disagree with that statement.

Use a hexadecimal string with leading zeros, to maintain framing.

ALWAYS send hexadecimal string in bigendian format.

I hope that helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.