7 years, 1 month ago.

SPI problems with Nucleo 64 STM32f401re

Hi,

I'm trying to use an SD card library with my STM32f401re Nucleo. I haven't been having any luck (can't mount card). To begin with I wanted to make sure SPI was working properly, so I've used the SPI hello world program, and hooked up a logic analyzer to the pins. The first strange thing is that I see the clock line going at 333kHz. I've tried selecting 1kHz, 100kHz and 1MHz, but I see no change in the SCK frequency. I am aware that PA_5 is also attached to the LED - could this be the problem?

Here's my code (incidentally this is hooked up to an SD card I don't actually expect to generate the correct response from the SD card, I just wanted to make sure the nucleo was sending what I thought it should be):

<<code>> /* mbed Example Program

  • Copyright (c) 2006-2014 ARM Limited
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
  • /
  1. include "mbed.h"
  2. include "mbed_debug.h"

SPI spi(D11, D12, D13); mosi, miso, sclk DigitalOut cs(D3);

int main() { while(1) { Chip must be deselected cs = 1;

Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(1000);

Select the device by seting chip select low cs = 0;

Send 0x8f, the command to read the WHOAMI register spi.write(0x8F);

Send a dummy byte to receive the contents of the WHOAMI register int whoami = spi.write(0x00); printf("WHOAMI register = 0x%X\n", whoami);

Deselect the device cs = 1; wait(0.1); } }<</code>>

Be the first to answer this question.