Skip to main content
JAlle.2
Associate II
December 31, 2020
Solved

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

  • December 31, 2020
  • 6 replies
  • 2816 views

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.

This topic has been closed for replies.
Best answer by TDK

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

6 replies

TDK
December 31, 2020

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""."
JAlle.2
JAlle.2Author
Associate II
December 31, 2020

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?

TDK
December 31, 2020

> 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""."
waclawek.jan
Super User
December 31, 2020

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

JAlle.2
JAlle.2Author
Associate II
December 31, 2020

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
TDKBest answer
December 31, 2020

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
JAlle.2Author
Associate II
December 31, 2020

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!

waclawek.jan
Super User
December 31, 2020

While you are supposed to read the entire boring manual, these are all very valid points to the quality of the given manual.

@Imen DAHMEN​ , can comebody please sweep through that manual and insert full pin names (e.g. "PA2, PA3, PA6, PA7"| instead of "PA2, 3, 6, 7") so they are searchable; and also insert remarks/footnotes to the pinout table, as JAlle.2 suggested above?

And, of course, all Disco manuals would deserve a respin (and removal of the "modern feel and look" where it was used ;-), and insertion of the schematics EVEN IF IT IS MORE WORK TO ST). The DiscoF4 manual is perhaps a good example how manual can be improved in time, especially the pinout table is excellent there. I know how ST frowns upon this kind of work, which in the view of management is unproductive. Yet it's the Disco boards which brought STM32 to the position they are now.

Thanks,

Jan

TDK
December 31, 2020

Valid points. Although, it does show up in a search for "PA6", which if you look at what the columns/notes mean, will get you the same information. That's how I found it.

0693W000006HIgmQAG.png

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