cancel
Showing results for 
Search instead for 
Did you mean: 

STM32l151RBT6A SPI issue

Parmin Nayani
Associate III
Posted on March 20, 2017 at 13:57

Hi all,

I am not able to get SPI working on stm32l151rbt6a. I have posted my initialization code below.

/* SPI1 init function */

void MX_SPI1_Init(void)

{

     GPIO_InitTypeDef GPIO_InitStruct;

     SPI_HandleTypeDef hspi1;

        __SPI1_CLK_ENABLE();            // clock ok

        /**SPI1 GPIO Configuration

        PA5     ------> SPI1_SCK

        PA6     ------> SPI1_MISO

        PA7     ------> SPI1_MOSI

        */

        GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;

        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

        GPIO_InitStruct.Pull = GPIO_NOPULL;

        GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;

        GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLED;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;

  HAL_SPI_Init(&hspi1);

  __HAL_SPI_ENABLE(&hspi1);

 }

I am writing a byte to DR and  waiting for RXNE bit to set. RXNE bit is never setting. What could be the problem? I have spent a lot of time trying various options but to no avail. Any help will be highly appreciated. Thank you in advance.

5 REPLIES 5
Khouloud GARSI
Lead II
Posted on March 21, 2017 at 15:38

Hi

Nayani.Parmin

‌,

I'd highly recommend you to refer to the SPI examples under

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubel1.html

package.

The 'SPI' examples are found under the path below:

STM32Cube_FW_L1_V1.6.0\Projects\STM32L152RE-Nucleo\Examples\SPI

Those examples runs on STM32L1xx devices; They will help you to correctly configure the SPI peripheral.

Khouloud.

Posted on March 22, 2017 at 04:16

Hi Khouloud,

As a matter of fact I used the code generated by Cube only. However I will go through the link, check and revert. If you have worked on this controller SPI, did you get it working? Thank you.

Posted on March 22, 2017 at 12:04

Hi

Nayani.Parmin

‌,

The examples are working conveniently.

Khouloud.

Posted on April 06, 2017 at 20:02

are you able resolve the issue.. ? if yes, can you please let me know the solution, i am encountering the same issue at my end.

Posted on May 15, 2017 at 11:14

Hi Sampath

Sorry I saw your post so very late. I have been able to get SPI working on STM32L151 controller. Let me know if you still have the problem. I will post the code.