SPI Master STM32f411

Any bugs you encounter with Flowcode should be discussed here.
Alan_37
Posts: 173
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 52 times
Been thanked: 25 times

Flowcode v10 SPI Master STM32f411

Post 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!
Last edited by Alan_37 on Tue Sep 10, 2024 10:32 pm, edited 1 time in total.

LeighM
Valued Contributor
Posts: 421
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 76 times
Been thanked: 232 times

Re: SPI Master STM32f411

Post by LeighM »

Could you attach your STM32f411 SPI Master Flowcode program?
Or a sample that demonstrates the issue?

Alan_37
Posts: 173
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 52 times
Been thanked: 25 times

Re: SPI Master STM32f411

Post 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.
Attachments
SPI TEST.fcfx
(13.64 KiB) Downloaded 214 times

LeighM
Valued Contributor
Posts: 421
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 76 times
Been thanked: 232 times

Re: SPI Master STM32f411

Post 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?

LeighM
Valued Contributor
Posts: 421
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 76 times
Been thanked: 232 times

Re: SPI Master STM32f411

Post 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

Alan_37
Posts: 173
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 52 times
Been thanked: 25 times

Re: SPI Master STM32f411

Post 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 3784 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 3784 times
.

is this something normal or I am doing wrong?

chipfryer27
Valued Contributor
Posts: 1367
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 330 times
Been thanked: 475 times

Re: SPI Master STM32f411

Post 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

Alan_37
Posts: 173
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 52 times
Been thanked: 25 times

Re: SPI Master STM32f411

Post 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

chipfryer27
Valued Contributor
Posts: 1367
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 330 times
Been thanked: 475 times

Re: SPI Master STM32f411

Post 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
Attachments
SPI-Interface.pdf
(427.14 KiB) Downloaded 207 times

mnfisher
Valued Contributor
Posts: 1279
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 122 times
Been thanked: 643 times

Re: SPI Master STM32f411

Post by mnfisher »

Can you also post the 'slave' code?

Martin

Post Reply