AnsweredAssumed Answered

STM32F429-Discovery, SPI problem

Question asked by Baev.Alexander on Feb 11, 2016
Latest reply on Feb 11, 2016 by Baev.Alexander

Hi.

I need SPI to connect a radiomodule NRF24L01. I'm using STM32F429-discovery. According to the UM1670 pins PE2 trhough PE6 are free (nothing is connected to them). PE2 can be used as SPI4-SCK, PE5 – SPI4-MISO, PE6 – SPI4-MOSI.

I cannot make SPI work. The part of the code is attached. I inserted a code assigning the pins as outputs just to check that the physical connection is good (I step through lines while debugging and watch physical changes on the pins with logic analyzer). The physical connections are good.

What did I do wrong?

Thanks!

GPIO_InitTypeDef GPIO_InitStruct;
SPI_InitTypeDef SPI_InitStruct;
     
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE ,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI4,ENABLE);
               
 /*  Test of connectors - should be deleted later */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_SetBits(GPIOE,GPIO_Pin_2);
GPIO_ResetBits(GPIOE,GPIO_Pin_2);
                 
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
                 
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_SetBits(GPIOE,GPIO_Pin_6);
GPIO_ResetBits(GPIOE,GPIO_Pin_6);
 /*  Test of connectors end */
                 
                 
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;                      
GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIOE, GPIO_Pin_2, GPIO_AF_SPI4);
GPIO_PinAFConfig(GPIOE, GPIO_Pin_5, GPIO_AF_SPI4);
GPIO_PinAFConfig(GPIOE, GPIO_Pin_6, GPIO_AF_SPI4);
     
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStruct.SPI_Direction= SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(SPIx, &SPI_InitStruct);
 
SPI_Cmd(SPI4, ENABLE);
SPI_I2S_SendData(SPI4, 0x12);

Outcomes