SPI Loopback in Simulink with STM32 Nucleo
이전 댓글 표시
Hi
I'm trying to do a simple loopback (I have connected pin D11 &D12) using a Nucleo F411RE and the SPI blocks in the STM32 support package. I am using the Spi Controller Transfer and I cannot seem to read back the data correctly, it just shows 0.
I've checked the output of the MOSI on an oscilloscope and it's definitely sending the data out. I think I'm missing something with the way to read SPI in Simulink Coder.

My settings:


Does anyone have any ideas?
Cheers
Amir
댓글 수: 2
Abhishek
2025년 9월 5일
Based on your description, this behavior could be related to a timing delay in how the Simulink model interacts with the SPI hardware. It's possible that the '0' you are seeing is because the looped-back data from a step is not available to the model until the next execution time step.
A good way to investigate this is to visualize the input and output signals together over time. This will help you confirm if a delay is the root cause.
You can test this hypothesis by replacing your `Display` block with a `Scope` block.
- Add a `Scope` block from the Simulink library and configure it to have two input ports.
- Connect the first port to the signal going into the `SPI Controller Transfer` block.
- Connect the second port to the signal coming out of the `SPI Controller Transfer` block.
When you run the model, observe the two waveforms on the Scope. If the output signal is a time-shifted version of the input signal, it would strongly suggest that there is a processing delay. This test is a reliable way to determine the exact behavior of the block in your specific setup.
Amir
2025년 9월 5일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 STMicroelectronics Discovery Boards에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


