cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Stm32F429 discovery SPI2 problem with NRF24L01 register read

sanjuchopracool
Associate II
Posted on December 20, 2015 at 20:58

I am trying to read register for NRF24l01 with STM32F429 Discovery. I am using SPI2 with PB13,PB14,PB15 as SPI2_SCK,

SPI2_MISO, SPI2_MOSI and PB12 as CE pin. When i read i get 0 always. Please suggest me what's wrong with this code.

static bool isSet = false;
void error()
{
while(1)
{
if(isSet)
GPIO_ResetBits( GPIOG, GPIO_Pin_14 |GPIO_Pin_13 );
else
GPIO_SetBits( GPIOG, GPIO_Pin_14 |GPIO_Pin_13 );
isSet = !isSet;
delay( 50 );
}
}
/* Exported macro ------------------------------------------------------------*/
#define CS_LOW() GPIO_ResetBits(GPIOB, GPIO_Pin_12)
#define CS_HIGH() GPIO_SetBits(GPIOB, GPIO_Pin_12)
uint8_t SendByte(uint8_t byte)
{
while(!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI2, byte);
while(!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE));
return SPI_I2S_ReceiveData(SPI2);
}
void InitSPI2()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
GPIO_InitTypeDef GPIO_InitTypeDefStruct;
GPIO_InitTypeDefStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitTypeDefStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitTypeDefStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitTypeDefStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitTypeDefStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitTypeDefStruct);
GPIO_InitTypeDefStruct.GPIO_Pin = GPIO_Pin_12;
GPIO_InitTypeDefStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitTypeDefStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitTypeDefStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitTypeDefStruct.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOB, &GPIO_InitTypeDefStruct);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
GPIO_SetBits(GPIOB, GPIO_Pin_12);
SPI_InitTypeDef SPI_InitTypeDefStruct;
SPI_InitTypeDefStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitTypeDefStruct.SPI_Mode = SPI_Mode_Master;
SPI_InitTypeDefStruct.SPI_DataSize = SPI_DataSize_8b;
SPI_InitTypeDefStruct.SPI_CPOL = SPI_CPOL_Low;
SPI_InitTypeDefStruct.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitTypeDefStruct.SPI_NSS = SPI_NSS_Soft;
SPI_InitTypeDefStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitTypeDefStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitTypeDefStruct.SPI_CRCPolynomial = 7;
SPI_CalculateCRC(SPI2, DISABLE);
SPI_Init(SPI2, &SPI_InitTypeDefStruct);
SPI_Cmd(SPI2, ENABLE);
}
int main(void)
{
// it will start sysTick
systemInit();
initSerial();
// for error blink
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOG, ENABLE );
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_14 |GPIO_Pin_13);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOG, &GPIO_InitStructure);
InitSPI2();
while( 1 )
{
for ( int i =0; i < 5; i++)
{
CS_LOW();
SendByte(i);
uint8_t d = SendByte(0xFF);
CS_HIGH();
tfp_printf(''Reg(%d) %d\n'', i, d);
delay(100);
}
}
}

1 REPLY 1
sanjuchopracool
Associate II
Posted on December 20, 2015 at 21:34

On Discovery PB15 and PB14 are used for USB OTG. they are not connected to expansion headers.That's why i was not able to get the data :p