cancel
Showing results for 
Search instead for 
Did you mean: 

SPI PIN Configuration for STM32F0

pic_micro
Associate II
Posted on January 10, 2015 at 10:14

Dear All,

I would be grate if any one could advice me that in which page the SPI pin configuration is showing in the ''RM0091Reference manual'' STM32F0

I mean,

What are the proper  Configure GPIO for MOSI, MISO and SCK pins.

What is the exact pin configuration 

in which page is showing above configuration

Thanks in advance

24 REPLIES 24
pic_micro
Associate II
Posted on January 25, 2015 at 18:02

Dear Sir,

Following sentence is saying that the proper operation for SD card, the SCK signal must between 100KHz and 400KHz

To ensure the proper operation of the SD card, the SD CLK signal should have a frequency in the range of 100 to 400 kHz

Does following code do it, if the processor is running at 8MHz which is STM32F05 discover board default internal clock is ( 8MHz)

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;

Please advice
Posted on January 25, 2015 at 19:16

Well the APB rather than the CPU clock. But if that's at 8 MHz, the SPI is 125 KHz.

The cards want something at or below 400 KHz during initial start up, before switching to a speed suited to the specific card. They should all work at 400 KHz, though frankly most of the current ones will operate significantly faster.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on January 26, 2015 at 17:21

Dear Sir,

Thanks for the reply As per the SD driver manual, it says

To communicate with the SD card, your program has to place the SD card into the SPI mode. To do this, set the MOSI and CS lines to logic value 1 and toggle SD CLK for at least 74 cycles. After the 74 cycles (or more) have occurred

Please advice that the, Isfollowing program correct for the above sentence

#define SD_CS_HIGH() GPIO_SetBits(GPIOA, GPIO_Pin_4)
int SD_Init(){
uint32_t i = 0;
SD_CS_HIGH(); /*!< SD chip select high */
/*!< Send dummy byte 0xFF, 10 times with CS high */
/*!< Rise CS and MOSI for 80 clocks cycles */
for (i = 0; i <= 9; i++){
SD_WriteByte(SD_DUMMY_BYTE); /*!< Send dummy byte 0xFF */
}
}

After executing above program. Is there any Technic to check that the SD card in now in the SPI mode?
Posted on January 26, 2015 at 18:56

Is there any technique to check that the SD card in now in the SPI mode?

Sending it commands, and requesting status?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on January 28, 2015 at 17:49

Dear Sir,

I further modified the program inserting one more functions

int SD_GoIdleState(void)
{
SD_CS_LOW(); /*!< SD chip select low */ 
SD_SendCmd(CMD0, 0, 0x95);
}

This is the function I used to send the command, So in my case CMD0

void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc){
uint32_t i = 0x00;
uint8_t Frame[6];
Frame[0] = (Cmd | 0x40); /*!< 
Construct
byte 1 */
Frame[1] = (uint8_t)(Arg >> 24); /*!< 
Construct
byte 2 */
Frame[2] = (uint8_t)(Arg >> 16); /*!< 
Construct
byte 3 */
Frame[3] = (uint8_t)(Arg >> 8); /*!< Construct byte 4 */
Frame[4] = (uint8_t)(Arg); /*!< Construct byte 5 */
Frame[5] = (Crc); /*!< Construct CRC: byte 6 */
for (i = 0; i < 6; i++)
{
SD_WriteByte(Frame[i]); /*!< Send the Cmd bytes */
}
}

Please advice that,Am I on correct track up to now?

Please note.

SD_WriteByte() function is not showing hare

Please advice how can I check the SD card response Can I used 16GB micro SD card for this experiment? My only requirement on this stage is to identify that the SD card is in the idle state (#define SD_IN_IDLE_STATE 0x01)