cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 SPI Problem

SPark.2
Associate

Hi, I'm using stm32f030cct6 and control the sx1276.

I configured SPI1 like that

void SPI1_Init(void)

{

SPI_InitTypeDef SPI_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

/*****************MOSI, MISO SCLK GPIO Config********************/

  /**SPI1 GPIO Configuration

  PB3   ------> SPI1_SCK

  PB4   ------> SPI1_MISO

  PB5   ------> SPI1_MOSI

  */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_0);

GPIO_PinAFConfig(GPIOB,GPIO_PinSource4,GPIO_AF_0);

GPIO_PinAFConfig(GPIOB,GPIO_PinSource5,GPIO_AF_0);

/******************Chip Select GPIO Config**********************/

//RF_NSS

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_SetBits(GPIOA,GPIO_Pin_15);

/******************SPI1 Config for SX1276************************/

  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_16; // 5 MHz

  //SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; // 10 MHz

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI1, &SPI_InitStructure);

  SPI_Cmd(SPI1, ENABLE);

}

and send data to sx1276, but occured problem.

uint8_t SpiInOut( uint8_t outData )

{

  /* Send SPIy data */

SPI_SendData8( SPI1, outData );

  while( SPI_I2S_GetFlagStatus( SPI1, SPI_I2S_FLAG_RXNE ) == RESET );

  return SPI_ReceiveData8( SPI1 );

}

in that fucntion, SPI1->SR register is 0x202 so I can't receive data.

what's the problem?, what should i do?

0 REPLIES 0