AnsweredAssumed Answered

SPI configuration

Question asked by Amor.Ben_amor on Jul 26, 2013
Latest reply on Aug 5, 2013 by Amor.Ben_amor
hello 
i have configure the SPI1 in the stm32F0 for a data acquisition from a sensor. I marked that the processor always enter in the RXNE interrupt  despite there is no  data in the MISO pin.

    /* SPI1 Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB| RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOF, ENABLE);
  
  
  
  /* SPI1 Config -------------------------------------------------------------*/
  SPI_InitStructure_Position.SPI_Direction = SPI_Direction_1Line_Rx;
  SPI_InitStructure_Position.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure_Position.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure_Position.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure_Position.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure_Position.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure_Position.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; 
  SPI_InitStructure_Position.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure_Position.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure_Position);
  
  /* Configure SPI1 pins: SCK & MISO */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 
  GPIO_Init(GPIOA, &GPIO_InitStructure);


  /* Configure PC5 pin: CS pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  


    /* Connect SPI_SCK */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0);


  /* Connect SPI_MISO */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0);
      /*SPI1 enable */
  SPI_Cmd(SPI1, ENABLE);
  SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,ENABLE);
  
  NVIC_InitStructure.NVIC_IRQChannel=SPI1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority=2;
  NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  NVIC_Init(&NVIC_InitStructure);



}

Outcomes