2020-05-22 09: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 */
}
}
2020-05-22 09:41 AM
Init seems fine. You don't need to do anything apart from enabling the clock and configuring the pins. Does your code detect the TXE flag and try to transmit data?
2020-05-22 10:41 AM
if(( LL_SPI_IsActiveFlag_TXE(hspi1.Instance)) && (ubNbDataToTransmit > 0)) so yes. I have no idea what the issue is and have been working on it for a few days.
2020-05-22 11:08 AM
Read out and check/post the relevant GPIO and SPI registers content.
JW
2020-05-22 12:07 PM
Just before while 1 after spi init
after 1st LL_SPI_TransmitData16 call, breakpoint on ubNbDataToTransmit--.
Not real sure how to read/show the relevant GPIO regs.
2020-05-22 12:26 PM
Just shown portb mode register here which is relevant to the spi being tagged to PB3, PB4, and PB5 I think.
Just after MX_GPIO_Init() not shown but toward the start of main.
Just after MX_SPI1_Init().
2020-05-22 01:55 PM
Could this be the issue? This is from header file stm32wbxx_nucleo.h. Do I need to redefine from GPIO A to GPIO B here and the relevant pins?
2020-05-23 04:10 AM
The binary numbers are extremely hard to read, next time please use hexadecimal.
GPIO_MODER looks good, AF set for PB3, 4, 5; but you did not post the AFR register's content.
SPI registers look good, the fact that RXNE is set after the transmit function makes me believe that the clock is output to physical SCK pin (otherwise the receiver in other STM32 SPIs does not work; I doubt the 'WB is an exception).
Did you observe the pins directly on the package? Isn't there a jumper or solder bridge on the board which you overlooked? See schematics and board manual.
JW
2020-05-23 07:38 AM
2020-05-23 07:44 AM
Ok, I took the same CubeMx file and disabled spi1 and made PB3,4,5 outputs so I could toggle them. I added the code shown below
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(GPIOB, PB7_Red_Pin);
HAL_GPIO_TogglePin(GPIOB, PB6_Green_Pin);
HAL_GPIO_TogglePin(GPIOD, PD5_Blue_Pin);
HAL_Delay(20);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
And on the test points on the board I measured the following on PB3, 4, and 5. I’ve ohmed each pin to each other plus to ground and surrounding pins and no shorts so I’m confident the hardware is ok.