cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 SPI voltages are low and the clock signal behaves unexpectedly

ASoli.2
Associate II

So I have been developing my custom board, based on the STM32F407VE chip, and have encountered an issue with the SPI1 bus. I was trying to set up an SD card module on the bus, using the SdFat library by Bill Greiman. I specified the CS pin to be PA4, which is the default CS for the SPI1 bus. Below is the connection diagram, as well as the chip's SPI1 bus pinout for reference. 0693W00000bhKsvQAE.png0693W00000bhKsqQAE.pngThe SD card fails to initialize, in particular, SPI library throws a timeout right here.

// initialize card and send host supports SDHC if SD2
  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;
  timeout.set(SD_INIT_TIMEOUT);
  while (cardAcmd(ACMD41, arg) != R1_READY_STATE)
  {
    // check for timeout
    if (timeout.timedOut())
    { 
      //Serial.println("timeout");
      error(SD_CARD_ERROR_ACMD41);
      goto fail;
    }
  }

The voltages on the SPI pins are very low, below 2V, although everything on the board is running on 3.3V. However, the I2C buses and other peripherals operate just fine, so power supply related issues seem unlikely.

Also, the clock signal looks not how a clock signal should look like.

0693W00000bhKsrQAE.jpgAt first, I thought I might be running it too fast, and attempted to lower the clock speed:

SPI.setClockDivider(255);

But it doesn't seem to even work. It doesn't seem to affect the frequency of the SPI clock signal at all.

I will be happy to provide any additional details, and grateful for any help in getting this thing to return a true.

SD.begin(SD_CS_PIN)

6 REPLIES 6

Look at the signal levels without a card in the socket.

Review the other end of the circuit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ASoli.2
Associate II

Without the card:

Clk 1.5V

Mosi 3V

Miso 0V

Cs 3V

​And with:

Miso 2V

Clk 1.5V

Mosi 3V

Cs 3​V, I've tried 3 different cards, 2 of them timeout in the same way, and one sometimes, around once every 2 attempts passes the block of code I posted above and fails on the next one, which is supposed to read some card ID register. It is super weird.

AScha.3
Chief II

why dont you use the SDIO ?

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

I've never used it. Do you have any good references for it? Also, if it requires different wiring than SPI, then I can't use it, as I'm working on a PCB, and I don't have the time to have a new one manufactured.

it should be much faster, esp. in 4 bit mode; but different wiring...shure.

so now you have to use SPi .

maybe you try: set pin speed low, to reduce reflections on the lines to sdcard.

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

Wondering about the quality of the scope/grounding

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..