cancel
Showing results for 
Search instead for 
Did you mean: 

SPI configuration

Cesar cfg
Associate II
Posted on July 26, 2013 at 08:00

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);

}

4 REPLIES 4
Posted on July 26, 2013 at 13:06

Sorry, I don't understand what the question is.

RXNE will set based on clock cycles on the SPI bus, what the data pin is doing is pretty irrelevant. If you don't clear the RXNE state in the interrupt it will keep re-entering.

I'd advise you to configure the NVIC prior to enabling the interrupt source.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on August 01, 2013 at 11:39

Hi Clive1,

My project is to get 18 bits from a sensor ,but in the stm32 we have just 16 bits maximum of data size  ,so do you have any idea to resolve my problem.

Thanks. 

Posted on August 01, 2013 at 13:15

If it can stream multiple words you could read 8x 18 as 9x 16 (144 bits) or 4x 18 as 9x 8 (72 bits)? Then separate your 18-bit words in memory.

Alternatively you could bit-bang the interface.

The STM32F0, as I recall, has move flexible SPI settings.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cesar cfg
Associate II
Posted on August 05, 2013 at 10:58

Thank you Clive for your reply.