Cannot get the SPI pins to toggle.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-05-22 9:23 AM
I'm using the project "SPI_FullDuplex_ComPolling_Master" in P-Nucleo-WB55.Nucleo/Examples_MIX/SPI in FW version 1.6.0. Works fine on the nucleo board. I've ported it to my board which uses pins PB5, PB4, and PB3. I'm using a crystal on my board. I did this same exercise with the UART projects and it works fine on the nucleo board as well as my board even though they use different UART pins. I cannot seem to be able to get any activity on the pins, MOSI or CLK, even though the spi instance is set correctly to each boards pins. Is there something I need to do to enable the pins on my board regarding the clocks?
If I just toggle the pins in code they toggle but no activity when transmitting via spi.
Any help would be appreciated.
MX_SPI1_Init();
/*##-1- Start the Full Duplex Communication process ########################*/
/* Enable SPI before start transmission */
LL_SPI_Enable(hspi1.Instance);
/*## Start the transmission process (using HAL Polling mode) #############*/
/* In main loop, Tx buffer is sent every 0.5 sec.
As soon as RX buffer is detected as full, received bytes are echoed on TX line to PC com port */
/* USER CODE END 2 */
while(1)
{
/* Check TXE flag to transmit data */
if(( LL_SPI_IsActiveFlag_TXE(hspi1.Instance)) && (ubNbDataToTransmit > 0))
{
/* Transmit 16bit Data */
LL_SPI_TransmitData16(hspi1.Instance, aaTxBuffer[ubTransmitIndex++]);
ubNbDataToTransmit--;
}
/* Check RXE flag */
if(LL_SPI_IsActiveFlag_RXNE(hspi1.Instance))
{
/* Receive 16bit Data */
aaRxBuffer[ubReceiveIndex++] = LL_SPI_ReceiveData16(hspi1.Instance);
ubNbDataToReceive--;
}
}
/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI1 GPIO Configuration
PB3 ------> SPI1_SCK
PB4 ------> SPI1_MISO
PB5 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
- Labels:
-
SPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-05-23 7:58 AM
Well, then if you are sure that GPIOB_AFR contains the expected values for PB3-PB5, then I don't know why you wouldn't see the SCK/MOSI waveforms, sorry.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-05-23 9:31 AM
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000);
works but the LL transmit in the original code does not. Any thoughts as to why that would be?
By the way, I appreciate all your help on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-05-23 10:07 AM
Try replacing
LL_SPI_TransmitData16(hspi1.Instance, aaTxBuffer[ubTransmitIndex++]);
with
hspi1.Instance->DR = aaTxBuffer[ubTransmitIndex++];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-05-23 11:38 AM
When I built the project with CubeMx I compared it to the project in the repository. That project had the BSP directory included which I think was messing up the CubeMx generated setup of the HAL.
I originally had this
Which would not work.
When I removed the file stm32wbxx_nucleo.c from the project like this
It works with LL and hspi1.Instance->DR.
I was trying to get away from the nucleo bsp but to get it running I added the bsp/file to my project thinking I needed it.
Not sure if you work with ST but you’ve been a big help.
Hope you have a great Memorial Day weekend.
Thanks again,
Barry

- « Previous
-
- 1
- 2
- Next »