AnsweredAssumed Answered

STM32F407 reading from SPI2 only get 0xff

Question asked by iggy.snabel on Feb 29, 2016
Latest reply on Mar 1, 2016 by waclawek.jan
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);

Outcomes