cancel
Showing results for 
Search instead for 
Did you mean: 

SPI3 Chip Select (NSS) not working

Fede Rico
Associate III
Posted on November 14, 2017 at 10:47

Hello there,

with my STM32F103, I'm working with the M25P40 SPI flash memory.

With cube32Mx I configured the SPI3 with Chip Select (NSS) hardware and I perform Read/Write/WriteRead operation with Interrupt.

My problem regards the NSS, in particular the NSS signal stay low after the read operation end and the:

  • HAL_SPI_RxCpltCallback
  • HAL_SPI_TxRxCpltCallback

are never invoked.

Looking the signal with Saleae Logic Analazer, I saw that NSS signal stay low.

0690X0000060PDqQAM.png

Instead, theHAL_SPI_TxCpltCallback is invoked.

This is the SPI3 initialization code generated by CubeMx:

 hspi3.Instance = SPI3;
 hspi3.Init.Mode = SPI_MODE_MASTER;
 hspi3.Init.Direction = SPI_DIRECTION_2LINES;
 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
 hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi3.Init.NSS = SPI_NSS_HARD_OUTPUT;
 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi3.Init.CRCPolynomial = 10;�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I don't know how to resolve this issue.

Thanks in advance!

#interrupt #spi-write-and-read #flash-memory #stm32f103
4 REPLIES 4
Posted on November 14, 2017 at 11:45

That's how it's supposed to work - read the RM.

If you want framing, you have to do it 'manually'.

JW

Posted on November 14, 2017 at 11:47

Hi Jan,

thank for the reply but frankly I don't understand your reply.

Could you please add more details?

Posted on November 14, 2017 at 13:08

RM0008, SPI chapter, Slave select (NSS) pin management subchapter:

The NSS signal is driven low when the master starts the communication and is kept

low until the SPI is disabled.

If you want to set the pin to 0 before communication starts and to 1 after communication ends,  you have to set it as GPIO and write the code to manipulate it.

JW

Posted on November 14, 2017 at 13:36

Thanks for the detailed explanation.

My question is: could be the HAL_SPI_RxCpltCallback related to the NSS signal?

I'm in trouble with the

HAL_SPI_RxCpltCallback, that is never invoked.

This is what I do to read the Flash Memory id:

HAL_SPI_TransmitReceive_IT(SPI_Handlers[channel], bufferIn, bufferOut, bufferSize)�?

where the buffer size is 20 because, the flash id is 20 bytes. Am I right? Or Should I set size as 21 (1 byte for the command and 21 for the read?