cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746 Discovery: spi slave nss input doesn't work correctly

TechMarc
Associate II

We use STM32F746 discovery board and run stm32f7 as spi slave with nss as sync signal between each byte. The master drives nss, clk and mosi pins. Clock is 250khz and processing is done in interrupt. Every 100ms 1 byte is transferred. Sometimes the slave misses single bytes.

Init code is shown below.

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)

{

GPIO_InitTypeDef GPIO_InitStruct;

 if (hspi->Instance == SPIx)

 {

  /*##-1- Enable peripherals and GPIO Clocks #################################*/

  /* Enable GPIO TX/RX clock */

  SPIx_SCK_GPIO_CLK_ENABLE();

  SPIx_NSS_GPIO_CLK_ENABLE();

  SPIx_MISO_GPIO_CLK_ENABLE();

  SPIx_MOSI_GPIO_CLK_ENABLE();

  /* Enable SPI clock */

  SPIx_CLK_ENABLE();

  /*##-2- Configure peripheral GPIO ##########################################*/

  /* SPI SCK GPIO pin configuration */

  GPIO_InitStruct.Pin    = SPIx_SCK_PIN;

  GPIO_InitStruct.Mode   = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull   = GPIO_PULLUP;

  GPIO_InitStruct.Speed   = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Alternate = SPIx_SCK_AF;

  HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct);

  /* SPI MISO GPIO pin configuration */

  GPIO_InitStruct.Pin = SPIx_MISO_PIN;

  GPIO_InitStruct.Alternate = SPIx_MISO_AF;

  HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct);

  /* SPI MOSI GPIO pin configuration */

  GPIO_InitStruct.Pin = SPIx_MOSI_PIN;

  GPIO_InitStruct.Alternate = SPIx_MOSI_AF;

  HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct);

  /* SPI NSS GPIO pin configuration */

  GPIO_InitStruct.Pin = SPIx_NSS_PIN;

  GPIO_InitStruct.Alternate = SPIx_NSS_AF;

  HAL_GPIO_Init(SPIx_NSS_GPIO_PORT, &GPIO_InitStruct);

  /*##-3- Configure the NVIC for SPI #########################################*/

  /* NVIC for SPI */

  HAL_NVIC_SetPriority(SPIx_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(SPIx_IRQn);

 }

}

static void SpiInit()

{

 SpiHandle.Instance        = SPIx;

 SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;

 SpiHandle.Init.Direction     = SPI_DIRECTION_2LINES;

 SpiHandle.Init.CLKPhase     = SPI_PHASE_1EDGE;

 SpiHandle.Init.CLKPolarity    = SPI_POLARITY_LOW;

 SpiHandle.Init.DataSize     = SPI_DATASIZE_8BIT;

 SpiHandle.Init.FirstBit     = SPI_FIRSTBIT_MSB;

 SpiHandle.Init.TIMode      = SPI_TIMODE_DISABLE;

 SpiHandle.Init.CRCCalculation  = SPI_CRCCALCULATION_DISABLE;

 SpiHandle.Init.CRCPolynomial   = 7;

 SpiHandle.Init.NSS        = SPI_NSS_HARD_INPUT;

 SpiHandle.Init.Mode       = SPI_MODE_SLAVE;

 if(HAL_SPI_Init(&SpiHandle) != HAL_OK)

 {

  /* Initialization Error */

  Error_Handler();

 }

}

Voltage on ports is 3,3 volts. When we connect oscilloscope on nss pin, no more data is lost?!?! Could be a problem with ground level or VCC??? When we use software slave management everything works fine. Any idea what causes the problem?

Thanks in advance

2 REPLIES 2

What is master? Isn't NSS too "tight", i.e. is there enough setup and hold time before and after transfer, as specified in the  SPI dynamic characteristics table and related timing diagrams in the datasheet?

JW

TechMarc
Associate II

Master is an atmel uc which generates the NSS correctly. Timing of NSS setup and hold is ok.

The error is fixed now. We connected two evalboard with short cables. On the NSS line there were short peaks which lead to the transfer errors. The peaks came from the clk and data lines. When we put the cable with NSS signal away from the other cables, everything works fine.

Thanks for your support

Marc