cancel
Showing results for 
Search instead for 
Did you mean: 

SPI2 not working in stm32f070

prateek agrawal
Associate II
Posted on October 04, 2017 at 07:37

Hello All

currently i am working in Fatfs with stm32f070 with spi1. 

when i move to spi2 its not working. 

i am trying multiple times but i cant get success. 

here is my init function

void SPIFlashInit(void)

{

SPI_InitTypeDef SPI_Struct;

GPIO_InitTypeDef GPIO_Struct;

uint32_t stat;

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB ,ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA ,ENABLE);

GPIO_Struct.GPIO_Pin = GPIO_Pin_15;

GPIO_Struct.GPIO_Mode = GPIO_Mode_OUT;

GPIO_Struct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_Struct);

GPIO_WriteBit(GPIOA,GPIO_Pin_15,Bit_SET);

// Configure SPI1 pins: SCK, MISO and MOSI

GPIO_Struct.GPIO_Pin =

GPIO_Pin_13

|

GPIO_Pin_14

 |

GPIO_Pin_15

;

GPIO_Struct.GPIO_Mode = GPIO_Mode_AF;

GPIO_Init(GPIOB, &GPIO_Struct);

//Configure I/O for Flash Chip select //

GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_0);

GPIO_PinAFConfig(

GPIOB

,GPIO_PinSource14,GPIO_AF_0);

GPIO_PinAFConfig(

GPIOB

,GPIO_PinSource15,GPIO_AF_0);

//SPI1 configuration

SPI_Struct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

SPI_Struct.SPI_Mode = SPI_Mode_Master;

SPI_Struct.SPI_DataSize = SPI_DataSize_8b;

SPI_Struct.SPI_CPOL = SPI_CPOL_Low;

SPI_Struct.SPI_CPHA = SPI_CPHA_1Edge;

SPI_Struct.SPI_NSS = SPI_NSS_Soft;

SPI_Struct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;

SPI_Struct.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_Struct.SPI_CRCPolynomial = 7;

SPI_Init(SPI2, &SPI_Struct);

SPI_RxFIFOThresholdConfig (SPI2,SPI_RxFIFOThreshold_QF);

SPI_Cmd(SPI2, ENABLE);

}

please ans me where i am wrong in this code.

1 REPLY 1
Brian Kling
Senior III
Posted on October 04, 2017 at 08:20

agrawal.prateek

‌ I see that you posted the same question in 2 forums. I can appreciate your desire to increase your chances of a response, but we discourage this practice, as then one thread may have the answer and the other one not, or both and then others are duplicating their efforts! I will lock this post and you can message me if you don't get a reply soon to your other one in the STM32 forum, which is the most active 😉

Be well and welcome to the community!

Brian