Page 1 of 2

SPI Master STM32f411

Posted: Tue Sep 10, 2024 12:43 am
by Alan_37
Hi,

So I am trying to communicate between an STM32f411 ( SPI Master ) and an Atmega328P (Spi Slave)

The first thing I notice is that when sending a Char from the master, the CLK Pulses are NOT present
so no SPI communication can take place.

I tried Software and also Channel 1, Same Problem

Please Fix this ASAP, as Nothing is working Here I tried I2c Slave on 328p Not working, I tried Uart Software on 328p Not Working
posted the Uart bug no one responded.

I am very disappointed!

Re: SPI Master STM32f411

Posted: Tue Sep 10, 2024 5:05 pm
by LeighM
Could you attach your STM32f411 SPI Master Flowcode program?
Or a sample that demonstrates the issue?

Re: SPI Master STM32f411

Posted: Tue Sep 10, 2024 8:21 pm
by Alan_37
Hi LeightM

Thanks for your reply for now I am just making sure everything works so

What I am doing is just INIT SPI master, Enable chip select, send char, 1 second delay and loop
have the scope connected to the CLK pin, but no clock is being outputted .

In the same file, I have a W25 flash and a micro SD card that use the SPI ( different Chip select ) and are working fine
so it should not be a matter of Config Register ,

Here is a quick FCFX attaced.

Re: SPI Master STM32f411

Posted: Wed Sep 11, 2024 9:55 am
by LeighM
I don't (yet) see anything wrong with the generated C code.
It's certainly very odd if it doesn't even toggle the clock output in software mode.

I presume the B1 CS pin is toggling, to prove the loop is running?

Could you do a simple "LED flash test" loop on A5 (CLK), using an output icon?

Re: SPI Master STM32f411

Posted: Wed Sep 11, 2024 11:16 am
by LeighM
Hi,
I've run the SPI test program on an STM32F446 (same code family) and the SPI ran OK, in both hardware and software mode.
Hope that helps.
Leigh

Re: SPI Master STM32f411

Posted: Wed Sep 11, 2024 9:04 pm
by Alan_37
Hi LeighM,

Thanks for your reply,
your comment about connecting an LED got me thinking, maybe the scope is not triggering
and slave is not working which is why I don't have any rs232 out of the uart.

So I connected the logic analyzer to investigate, and sure enough to my surprise there it was
this is when sending a char.
.
SPI1.jpg
SPI1.jpg (18.05 KiB) Viewed 9442 times
.
now when I try to receive 2x chars something strange is happening the master sends 0x55 twice
.
Spi2.jpg
Spi2.jpg (36.7 KiB) Viewed 9442 times
.

is this something normal or I am doing wrong?

Re: SPI Master STM32f411

Posted: Wed Sep 11, 2024 9:49 pm
by chipfryer27
Hi

Sorry if I'm off track here, been busy and only paying cursory glances through posts.

SPI is always bidirectional. When you wish to send anything it must be "clocked" in and out. That's easy to imagine when sending, but when receiving from a Slave, something must also be getting clocked out of the Master simultaneously (and vice-versa). As you send you also receive.

I've not had a chance to look at your chart, but it sounds perhaps like a buffer hasn't been cleared or set properly. I won't realistically get a chance to look at anything until the weekend (at best).

No doubt Leigh will explain things far better than I ever could :)

Regards

Re: SPI Master STM32f411

Posted: Wed Sep 11, 2024 10:44 pm
by Alan_37
Hi chipfrier , thanks for your reply

Yes , clock should always be provided by the master
And since the master is sending a char and then trying to receive another 2 chars , it should be providing clock for the slave to send the data , now the slave is not working but i have some questions,

Why the master is sending 0x55 when it should be only
Providing CLK and listening for incoming data ?


Also I was expecting the master to continue providing CLK until a sort of timeout kicks in , which it is also not happening

Re: SPI Master STM32f411

Posted: Thu Sep 12, 2024 5:32 am
by chipfryer27
Hi

Each device Master/Slave has a buffer that simumtaneously gets clocked out/in. Whenever the Master sends anything this buffer is clocked out. Same in receive, as it receives the buffer contents are also clocked out. There is no scenario whereby you would only be providing a "clock" without transmitting data.

I can't find it just now, but I have a document somewhere that helps explain, meanwhile the attached from AD may help slightly. Benj (I think) wrote an informative piece on SPI / I2C in the Wiki.

Sorry to be brief heading out now.

Regards

Re: SPI Master STM32f411

Posted: Thu Sep 12, 2024 2:32 pm
by mnfisher
Can you also post the 'slave' code?

Martin