2017-04-11 10:10 AM
Hello,
right now I am facing some probems getting my STM32F407 to work as an SPI slave. The SPI is rightly configured and uses a hardware NSS. Furthermore I use HAL Drivers.I checked the transmitted SPI signals with a logic analyzer. They look fine. So the disered signal is applied to the pins according to my CubeMX configuration.Debugging yield to the cunclusion that HAL_SPI_STATE_BUSY_RX is always true. So my guess is, that because ofHAL_SPI_STATE_BUSY_RX is always true the HAL_SPI_RECEIVE() isn't finished and will never be executed HAL_SPI_RxCpltCallback().
Are aware of such issues? Are there any recommendations how to solve this problem? Can you provide a working code example for a SPI slave besides the examples in CubeMX ? Kind regards,Simon2017-04-12 02:36 AM
Hi,
For Hardware mode, refer to ''Slave select (NSS) pin management'' section in the reference manual and check
your configuration according to the alternate function table.
You should check the peripheral is clock enabled and make nss software as an alternative.
Imen
2017-04-12 04:47 AM
Hi Imen,
thanks for your reply. This section only shows the management for the Master. In my case I want to configure my STM32F4 as a SPI slave device with a hardware NSS. Following is my config code for the spi peripheral:
void MX_SPI1_Init(void) {
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_SLAVE;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{ Error_Handler();
}
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { GPIO_InitTypeDef GPIO_InitStruct; if(spiHandle->Instance==SPI1) {
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA4 ------> SPI1_NSS
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI */
GPIO_InitStruct.Pin = GPIO_PIN_4|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_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */ } ...... }