Skip to main content
stephan2
Associate
February 29, 2016
Question

STM32F407 reading from SPI2 only get 0xff

  • February 29, 2016
  • 3 replies
  • 1006 views
Posted on February 29, 2016 at 10:39

Dear STM32 users

I am new to STM32 but have experience in many other architectures. I got into everything up and running pretty quick (blinking LED, sending UART ... ). But now I'm stuck with no clue what so ever.

I attached an ADC to the SPI2 on my STM32F407. Sending the configuration works perfectly and the ADC seems to get it (SPS match the settings). My digital scope shows that the ADC is sending valid information to the MISO (PI2). But no mater how I try to read the data, I only get 0xff. I tried using the HAL_SPI_TransmitReceive() and tried directly access SPI2->DR after TXE,RXNE and BSY flags went low.

HELP I'm getting suicidal.... I attached my configuration that should init the SPI interface. I am using IAR with init code copied from STM32Cube MX.

/*

PB9     ------> SPI2_NSS

PI3     ------> SPI2_MOSI

PI2     ------> SPI2_MISO

PI1     ------> SPI2_SCK

*/

GPIO_InitStruct.Pin = GPIO_PIN_9;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_2 |GPIO_PIN_1;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);

__SPI2_CLK_ENABLE();

// setup SPI

hspi2.Instance = SPI2;

hspi2.Init.Mode = SPI_MODE_MASTER;

hspi2.Init.Direction = SPI_DIRECTION_2LINES;

hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;

// Prescalers > 8 are not working with HAL_SPI_Transmit !!!

hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;

hspi2.Init.TIMode = SPI_TIMODE_DISABLED;

hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;

hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;

hspi2.Init.CRCPolynomial = 7;

HAL_SPI_Init(&hspi2);
    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    February 29, 2016
    Posted on February 29, 2016 at 13:27

    Maybe PI2 pin not soldered down properly? Which package are you using?

    JW
    stephan2
    stephan2Author
    Associate
    March 1, 2016
    Posted on March 01, 2016 at 10:55

    It is a UFBGA176. I rewired the setup and use SPI1 now with different Pins. Suddenly it works. Must be defective input if no one else got trouble using SPI2.

    thx

    waclawek.jan
    Super User
    March 1, 2016
    Posted on March 01, 2016 at 11:20

    > It is a UFBGA176.

    Humm....

    > Must be defective input if no one else got trouble using SPI2.

    Most prominently, ST uses specifically the PI1..PI3 pins, in the two-boards-SPI demo in [STM32F4xx_DSP_StdPeriph_Lib_V1.6.0]\Project\STM32F4xx_StdPeriph_Examples\SPI\SPI_TwoBoards\SPI_DataExchangeDMA\

        - Connect BoardA SPI2 SCK pin  (PI.01) to BoardB SPI2 SCK pin  (PI.01)

        - Connect BoardA SPI2 MOSI pin (PI.03) to BoardB SPI2 MOSI pin (PI.03)

        - Connect BoardA SPI2 MISO pin (PI.02) to BoardB SPI2 MOSI pin (PI.02)

    As this demo is to be run on EVAL boards which DO use chips in UFBGA176, it's unlikely this is a yet-uncovered hardware bug.

    JW