2018-07-13 09:36 AM
Hi,
I am working on Nucleo-144 SPI. The NSS GPIO ios PA4. The only way I can have the NSS high is use
__HAL_SPI_DISABLE() function. The HAL_GPIO_WritePin() just never work.
I can see from the scope to verify it. Doesn't seems to be the right way to turn off the SPI for set NSS high.
Anyone has experience turn NSS high/low?
/**SPI1 GPIO Configuration
PA4 ------> SPI1_NSS PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */HAL_GPIO_WritePin( GPIOA, GPIO_PIN_4, GPIO_PIN_SET ); // NSS1 high
__HAL_SPI_DISABLE(m_spi);
Thx
2018-07-13 09:58 AM
You can't easily use the same pin with 'alternate' pin setting (that happens if you use the hardware NSS signal) assigned to the SPI interface and with output setting (simple GPIO). Check the corresponding reference manual:
'Alternate function configuration: ... The output buffer is driven by the signals coming from the peripheral (transmitter
enable and data) ...'. Peripheral here means SPI interface.Either 'automatic' or 'manual', but not both at the same time ...
2018-07-13 12:06 PM
I am assuming calling HAL_SPI_Transmit/Receive function doesn't automatically turn off NSS. The NSS always high after the function.
I am looking for a way to turn NSS on/off before/after the HAL function.
Thx
2018-07-13 12:46 PM
>>
The HAL_GPIO_WritePin() just never work.
Configure the pin as a GPIO. Sounds like you're not doing that properly. Show code, then people don't have to guess.
2018-07-13 01:03 PM
Here is the code code configing SPI GPIO. Thx
GPIO_InitTypeDef GPIO_InitStruct;
if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 *//* USER CODE END SPI1_MspInit 0 */
/* SPI1 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_MEDIUM; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);}
2018-07-13 04:21 PM
Dick Lin wrote:
I am assuming calling HAL_SPI_Transmit/Receive function doesn't automatically turn off NSS. The NSS always high after the function.
I am looking for a way to turn NSS on/off before/after the HAL function.
'Assuming' isn't very useful. Either it does or it does not. The inactive state of NSS is high, so what's the problem after all? And, as I said: Either the SPI is configured to activate/deactivate NSS automatically (and NSS as 'alternate function'), or this had to be done manually. In the latter case the SPI *MUST NOT* control NSS, but the pin you intend to use as NSS *MUST* be configured as a normal GPIO.
2018-07-15 12:50 AM
I think you described the way, SPI with HW NSS is supposed to work on STM32s. The SPI HW NSS is, how ever, known to have bugs in some STM32-chips.
From F103 fererence:
NSS output enabled (SSM = 0, SSOE = 1)
This configuration is used only when the device operates in master mode. TheNSS signal is driven low when the master starts the communication and is keptlow until the SPI is disabled.2018-07-15 02:10 PM
It's not a mistake.
Contact NSS should work this way.2018-07-15 04:45 PM
I kinda of feel that way since in HAL transmit/receive function there is a check to enable the SPI.
This is the only MCU I have been experienced to disable SPI in order to active high CS.
Thx
2018-07-15 09:08 PM
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; // This is NOT GPIO mode
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
A pin you configure in AF mode is not going to be controllable via HAL_GPIO_WritePin( )