cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 SPI2 with GPIOB AF partial work

michelemancini2
Associate III
Posted on November 03, 2012 at 12:38

Hi, I connect SD card to the stm32f0 discovery. I use the pin GPIOB pin 13, pin 14 , pin 15 use to alternate function.

The configuration work partial, sck and the MOSI work but the program stop to run when there is this funcion:

static BYTE stm32_spi_rw( BYTE out )
{
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET)
{
}
SPI_SendData8(SPI_SD, out);
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET)
{
}
return SPI_ReceiveData8(SPI2);
}

the program stop in the second line: while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) { } Why? This is the configuration: void power_on (void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; volatile BYTE dummyread; /* Enable GPIO clock for CS */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Enable SPI clock, SPI2 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); /* Enable SCK, MOSI and MISO GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); card_power(1); socket_cp_init(); socket_wp_init(); for (Timer1 = 25; Timer1; ); /* Wait for 250ms */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_0); GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0); /* Configure I/O for Flash Chip select */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_Init(GPIOC, &GPIO_InitStructure); /* De-select the Card: Chip Select high */ DESELECT(); //Pin configurazione (SCK MISO MOSI) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI configuration */ SPI_I2S_DeInit(SPI2); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_CalculateCRC(SPI2, DISABLE); SPI_Cmd(SPI2, ENABLE); /* drain SPI */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET) { ; } dummyread = SPI_ReceiveData8(SPI2); }
0 REPLIES 0