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-23 07: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
2020-05-23 09:31 AM
2020-05-23 10:07 AM
Try replacing
LL_SPI_TransmitData16(hspi1.Instance, aaTxBuffer[ubTransmitIndex++]);
with
hspi1.Instance->DR = aaTxBuffer[ubTransmitIndex++];
2020-05-23 11:38 AM