cancel
Showing results for 
Search instead for 
Did you mean: 

NSS input not take into account on SPI SLAVE

Amez-Droz.Philippe
Associate II
Posted on January 18, 2017 at 10:47

I have a system with 1 STM32F407 and 3 STM32F401. The 407 is the master  of a communication with SPI with the 3 slaves. On the slave a use SPI in slave mode with DMA in RX/TX. On the slaves the input NSS is used in hardware mode. I have of course three GPIO on master which allow to select one slave after each other. When I try to ask a slave I receive it answer BUT all the three slave answer at the same time. It's like the slave do not take into account the NSS pin.

I have configured the system with STMCube.

I use the HAL library.

/* SPI2 init function */

void MX_SPI2_Init_STEPPER(void)

{

  hspi2.Instance = SPI2;

  hspi2.Init.Mode = SPI_MODE_SLAVE;

  hspi2.Init.Direction = SPI_DIRECTION_2LINES;

  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi2.Init.NSS = SPI_NSS_HARD_INPUT;

  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi2.Init.TIMode = SPI_TIMODE_DISABLED;

  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;

  hspi2.Init.CRCPolynomial = 10;

  HAL_SPI_Init(&hspi2);

}

void MX_DMA_Init_STEPPER(void)

{

  /* DMA controller clock enable */

  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */

  HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);

  HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);

}

    HAL_SPI_TransmitReceive_DMA(&SPI_HMI,(uint8_t *)&txAxisBuffer[0],(uint8_t *)&rxAxisBuffer[0],20);

Has someone a solution for me?

Thank you in advance.

#dma-spi-slave-nss-hardware
5 REPLIES 5
Imen.D
ST Employee
Posted on January 18, 2017 at 12:54

Hello

Amez_Droz.Philippe

,

For Hardware mode, refer to 'Slave select (NSS) pin management' sectionin the reference manual and check

your configuration according tothe alternate function table andDMAconfiguration.

Also, you can review this discussion

https://community.st.com/0D50X00009XkVu6SAF

,it may helpful for you.

STM32CubeF4

v

1.0

firmware packageprovides a full set of SPI examples which canhelp you to identifyyourproblem and confirm if it seems related to the hardware or software environment:

STM32Cube_FW_F4_V1.0\Projects\STM32F4-Discovery\Examples\SPI

Hope this helps you.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
S.Ma
Principal
Posted on January 18, 2017 at 18:46

As an alternative, make nss software, and on each slave, use exti interrupt to activate the processing of the dma transferred data at the rising edge and re-prep the dma for the next transfer. Use exti falling edge to activate MISO pin.

Posted on January 18, 2017 at 22:31

Thank you IMEN D for your very fast answer.

Ig  I read

https://community.st.com/0D50X00009Xki6JSAR

I understand that there is perhaps a bug in the STMCubeMX 4.13 around NSS.It should be corrected in version 4.14. If someone can saya me what are the modification to do in the soft generated by version 4.13 it would be nice because I modify the fille generated a lot before use them (use of the same software (byte to byte) for different plateform) The link in 

https://community.st.com/0D50X00009Xki6JSAR

is nom more valid.

Thank you very much.

Posted on January 18, 2017 at 22:32

Thank you KIC842852. It's a good idea, I will use it if it's not possible to have a correct solution without make-up.

Thank you again.

Best regards.

Posted on January 19, 2017 at 09:46

Hi

Amez_Droz.Philippe

,

I recommend you to use thethe last version of your Cube firmware and CubeMx 4.0 which containsupdates to fix issuesand enhancements implementation as mentioned in the '

http://www.st.com/content/ccc/resource/technical/document/release_note/b2/02/4b/e3/81/32/49/c4/DM001076pdf/files/DM001076pdf/jcr:content/translations/en.DM001076pdf

'.

Hereis the invalid link

https://community.st.com/0D50X00009XkeY6SAJ

.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen