cancel
Showing results for 
Search instead for 
Did you mean: 

SPI not working with MISO connected to 3V and 0V

JAlle.2
Associate II

I am trying to code SPI functionality to connect with an external 16-bit ADC. The STM32 only receives data from the ADC, so only a MISO and SCLK line, along with a Conversion/CS line is required. I am currently using the 32F072BDISCOVERY board to test my code. Unfortunately, I do not have access to the ADC yet, so to perform simple testing to see if my SPI code is working, I figured I could set the MISO line to ground to receive all 0s or to 3V to receive all 1s. However, no matter what I connect the MISO line to, I only receive 1s.

To make things simple, I set the SPI peripheral data size on the STM32 to 8 bits.

Here is my code. Super simple so I don't know what could be going wrong here.

uint8_t spi_value[1];

HAL_SPI_Receive(&hspi1, spi_value,1,1000);

I am reading out the value over UART and checking it in the live variables section in the debugger. It always is 255, which is the equivalent of all 1s.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

PA6 is not available at the pin header by default as it's connected to the linear touch sensor. It requires some reconfiguration to expose it at the pin interface.

0693W000006HITTQA4.png 

The user manual has a good amount of information on this and other things:

https://www.st.com/resource/en/user_manual/dm00099401-discovery-kit-for-stm32f0-series-microcontrollers-with-stm32f072rb-stmicroelectronics.pdf

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

11 REPLIES 11
TDK
Guru

Did you initialize the pin in alternate function mode? And enable the relevant GPIO clocks?

If you feel a post has answered your question, please click "Accept as Solution".

I am using the STM32CUBEIDE with the MX perspective to generate the code for me. Wouldn't this automatically set the pin and GPIO clocks? I just double checked however and the pins are set to be SCLK and MISO functions. I am not quite sure how to enable and disable GPIO clocks. Is that the APB1 peripheral clocks?

> Wouldn't this automatically set the pin and GPIO clocks?

Yes, it should.

I would verify with a multimeter that the pin takes on the value you expect, and ensure that no other circuitry is on that pin. Also be aware solder bridges can be present which connect/disconnect MCU pins with external header pins.

If you're stuck, I'd also verify that the SCK line is toggling as expected when you receive a byte.

If you feel a post has answered your question, please click "Accept as Solution".

AHHH. I switched to using SPI2 and it is working now. Is it possible that my SPI1 is broken? The amount of time I spent trying to debug this - so frustrating.

Thanks for all your help!

> Is it possible that my SPI1 is broken?
No, I don't think it's realistically possible that ST would put out a chip where SPI1 flat out didn't work. There's another explanation somewhere.
If you feel a post has answered your question, please click "Accept as Solution".

Which MISO pin was the "not working" one? Isn't the MISO pin in question connected to some resource/pin/button/etc. on the board?

JW

The "not working" pin is PA6. I'm not entirely sure what else it's wired up to. If it is wired to something else that's preventing me from using it, why would they break out that pin to a header on the board in the first place?

TDK
Guru

PA6 is not available at the pin header by default as it's connected to the linear touch sensor. It requires some reconfiguration to expose it at the pin interface.

0693W000006HITTQA4.png 

The user manual has a good amount of information on this and other things:

https://www.st.com/resource/en/user_manual/dm00099401-discovery-kit-for-stm32f0-series-microcontrollers-with-stm32f072rb-stmicroelectronics.pdf

If you feel a post has answered your question, please click "Accept as Solution".
JAlle.2
Associate II

Ah well that'll do it. Pretty frustrating how hidden that detail seems to be. I feel like something like that be made more visible and clear in the user manual. I mean now it makes sense that its located in the solder bridge section and I'll know to look there from now on, but for someone new to embedded programming like me, if I was looking to use SPI on the dev board, I would intuitively look for a section on SPI or PA6 pin, not the solder bridge section and linear touch sensor. There's a whole section on the pins and their functions, why not make some kind of comment there or have some kind of asterisk to bring your attention to it! I did scan the document a couple times before but you can't even find it if you use ctrl-F to search for 'PA6' because of the comma and other pins they use between PA and 6.

Thanks for your help TDK and JW!