2024-06-27 12:05 PM - edited 2024-06-27 12:06 PM
Hi Community,
I'm new to working with STM32 microcontrollers and I'm encountering a challenge when transmitting data through SPI on my STM32 Nucleo board. I'd appreciate some guidance from the experienced members of this community.
My Goal:
The Problem:
Regardless of the data I send, I consistently see a doubling of the value on my logic analyzer. For example, sending 6 results in seeing 12 displayed. It seems like a constant shift is happening, and I'm unsure of the cause.
My Code Snippet:
const uint8_t Value1 = 0b10; while (1) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, RESET); HAL_SPI_Transmit(&hspi1, (uint8_t *)&Value1, 1, 100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, SET); HAL_Delay(2000); }
Attached Screenshots:
Seeking Assistance:
By reviewing the screenshots and considering my code, I'd be incredibly grateful if someone could help me understand, one more thing the CS pin is handled manually.
Thank you so much in advance for any support!
Solved! Go to Solution.
2024-06-27 12:20 PM
Hi,
i cannot see much from your LA pic...too small.
But ... seems, your LA is set on falling edge, while you set in Cube rising edge (1. edge);
so try setting both the same : set in Cube "2. edge" - and see.
2024-06-27 12:20 PM
Hi,
i cannot see much from your LA pic...too small.
But ... seems, your LA is set on falling edge, while you set in Cube rising edge (1. edge);
so try setting both the same : set in Cube "2. edge" - and see.
2024-06-27 01:14 PM
Sorry for the small size of the image, but you're right I set the clock phase to 2 Edge and it's working fine.
Thank you @AScha.3 !
If it's okay for you to explain it to me, why 1 Edge is causing extra 0 ?
2024-06-27 01:38 PM - edited 2024-06-27 01:41 PM
Hey, its shifting in at the edge, you set. So anything might come out, 0->1 , or 1->0 , on all bits; so shifting the whole "result" up or down, depending on the error.
Wrong is wrong...the SPI basically is not very complex, but the point of decision is important: 1 or 0 now .
So if you set this wrong...it might work, sometimes, depends on timing, or never.
But to see this, you need a scope (or LA) with much more resolution, than the signal, then you know, what happens.
Or just try...not so many possible settings. (only 4 .. rising, falling, 1. or 2. edge)