cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL_SPI_Library on Blue Pill

NicoNX650
Associate III

Title edited to note that this relates to a Blue Pill board.


Hello everyone,
I'm starting a learning journey into the STM32 world, specifically studying the HAL library (my past programming experiences didn't rely on ready-made libraries).
Right now (after tinkering with GPIOs, LCD management, etc.) I'm working on the SPI dialogue. I have two STM32F103CBT6A development boards, one configured for "Full Duplex Master" and one for "Full Duplex Slave."
When trying to send 10 static bytes (10, 20, 30, 100) from both the master and slave sides using the "HAL_SPI_TransmitReceive_IT(&hspi1, TX_Buffer, RX_Buffer, 10)" function, I expect the oscilloscope to see the MOSI line equal to the MISO line without any offsets. This happens for a few seconds after resetting the slave (image 1), but then the bytes on the MISO line shift (image 2). Furthermore (I'm viewing the data received from the slave on an LCD) when this problem occurs, the slave also doesn't receive correctly.
After adjusting the codes for 10-byte transmission, I wanted to expand it to 150 bytes.
Thanks in advance to anyone who can point out where I'm going wrong.

27 REPLIES 27

Your video is only 4 seconds long but has *way* more than 4 transmissions. It is constantly triggering. Was it really using the same code you showed? The code presented looks like it should work.

 

Does this problem also occur if you decrease the SPI clock rate (keeping the same core clock speed)?

 

The signal doesn't really get out of sync, it just looks like sometimes there is noise on the line which gets the bits wrong. It re-syncs itself which would not happen. How are the two boards connected? Show a picture of the full setup. I think this is a hardware issue, not a software one.

If you feel a post has answered your question, please click "Accept as Solution".

@NicoNX650 wrote:

P.S. I just bought two Nucleo boards 


Good move! Which Nucleos did you get?

There should be a ready-to-go example for SPI between the 2 Nucleo boards ...

See also in the Wiki: Configure SPI to communicate between two boards

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Dear TDK,

our video is constantly triggered becuase our scope is set in "Normal Mode" only to help the end user understanding.

We tried all the values of prescale of the SPI clock.

We have two blue pill on a bread board and the line is connected through wire. I know that it is not a good set-up but it's only a test in our workbench (noise sources such as switching converters, etc. are absent).

Once we're familiar with this MCU, we'll build our own PCB, as we've done in the past with other brands (the demo boards are just a starting point).
The "sliding" is systematic, so I rule out noise. At this point, if you don't see any particular anomalies in the codes, we'll wait for the Nucleos to arrive.

Thanks for your support, anyway.

Dear Andrew,

thanks for your reply, We bought NUCLEO-F401RE boards.

We hope that this could help us with development, because communication between different MCUs is essential for power converter manufacturers like us.
I'll update the post as soon as I receive the new boards.
Thanks again

> our video is constantly triggered becuase our scope is set in "Normal Mode" only to help the end user understanding.

No, this is not what is happening. The waveform is being updated on each trigger. The blue waveform changes 20+ times in the 4 second period. Something else is going on.

If you feel a post has answered your question, please click "Accept as Solution".
Maxime_MARCHETTO1
Community manager

Hello @NicoNX650,

The product you are using is a clone of a genuine ST product.

To get the support you need, please contact the third party you purchased this product from.

For assurance of buying authentic ST products, we recommend purchasing exclusively through our official distributors, which you can find listed here: ST Official Distributors.

Best regards,

Maxime


@NicoNX650 wrote:

I'll update the post as soon as I receive the new boards.


Best to start a new thread in the STM32 MCUs Boards and hardware tools forum once you have a genuine ST board.

You can always give a link back to this thread for reference, if necessary/helpful.

 

I would recommend starting from scratch with the above-mentioned ST examples...

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Dear Maxime,

thanks for your reply.

As I told in the last post, now I bought NUCLEO-F401RE boards. So in the next days I will continue my tests with genuine ST parts.

Best Regards