cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 SPI Transmit Problems

Will1
Associate II

I have been following a course Mastering microcontroller with STM32, and the emphasis of this course is to walk the student through the architecture of STM32 MCU's, and develop the driver's for GPIO, SPI. I2C, and USART from scratch.

I have an STM32F429 dev board with LCD screen. At this stage of the course, it is the first time trying to use the SPI protocol so I am only transmitting information to a slave (arduino - code written by the professor). My issue is that even when I don't have a slave connected, and just my logic analyser, nothing is toggling (chip select, clock, or MOSI) even though (from what I can tell) all my bit positions within each appropriate register is correctly toggled. I have attached an image that shows within OneNote all the registers correctly toggled after I enable my SPI2 peripheral.

What I do notice is, that after I use my send data function (for sending the length of message information) my status register is fine with no errors (each time I use my send data function my RXNE bit is setting for some reason), but after I use my send data function for my actual message (I'm sending a text string) it presents and error. The OVR flag which is an information receiving error, the input data register is not being read before it receives new information. The thing is I should have zero information received. I only have the SCLK, MOSI, and NSS (CS) pins connected. So this is another peace of the puzzle that I'm not sure how to go about.

to summarise:

  • My GPIO clocks and SPI2 clock are enabled
  • SPI control registers hvae SSI,SSM, and Master enabled, with CPOL and CPHA LOW.
    • 8 bit communication

I have attached my project in hopes that someone can test this out to see if this code works for them, as I'm not sure what to do anymore or how to proceed debugging. Does anything sound really wrong?

If I am missing information, or if I can provide further clarification please let me know.

Thanks everyone!

6 REPLIES 6

If I understand correctly, in 006spi_tx.c you've used SPI2 and PB12-PB15, but you've shown us GPIOA (with SPI1), so check GPIOB's settings. Also make sure you measure on those pins.

OTOH, in 007spi_txonly_arduino.c you use PA4-PA7 and SPI3, which is not a match, see Table 9. Alternate function mapping in the datasheet.

> I should have zero information received

In SPI, you can't disable the receiver. If there is no pin mapped to it, it simply receives all zeros.

JW

Will1
Associate II

Thanks JW for the response!

Sorry for the brutal commenting and labelling of a couple of functions, I can see it might be hard to follow.

006spi_tx.c isn't part of the build, so it won't effect flashing of the MCU.

But great catch on the 007spi_txonly_arduino.c, I was not careful about using the correct SPI(1,2,3) with the proper I/O's. I've updated my code.

>In SPI, you can't disable the receiver. If there is no pin mapped to it, it simply receives all zeros.

Right, I agree, but that is not the case. You can see that my MISO within my SPI_GPIO2Init function is disabled, and yet I'm getting the OVR flag.

Later today I'll update and see if anything changes!

Cheers

S.Ma
Principal

Go debug mode, view the peripheral registers for GPIO and SPI, check for anything strange.

SPI mode, use 4 wire bidirectional mode even if MISO is not going to a GPIO pin.

NSS being SW controlled (as GPIO, manually controlled)

The overflow is probably because you don't read the incoming bytes, even to trash them.

However, either you use the BUSY flag to know when the SPI is done working, or use RXNE flag.

Writing SPI.DR will generate the SCK pulses and push the data OUT on MOSI while MISO is sampling a byte.

TXE pops just after you write the data to send, while RNXE will pop once all 8 SCK clocks have been through.

Will1
Associate II

So I have updated my project based on JW's findings, but still no information is being sent. I have attached the updated project zip file. I also have attached an image that has two sub images, one being looking at the SR reg after I step over the first time I send the length information (which presents no errors) and the second sub image is when i send the actual image (the OVR Flag is being set).

How should I proceed to troubleshoot this? All the relevant register bit positions after I enable SPI3 seem to be correctly toggled.

Will1
Associate II

Here is the updated project

Will1
Associate II

Is anyone willing to look at my project to help? I have asked friends to look this over, and they can't find anything wrong either. I know my board isn't broken because I've used other SPI repositories and it's worked.