2021-05-20 12:18 AM
Hi,
I have imported the example project TX_CMSIS_Wrapper and I wanted to integrate SPI5 with it. After initialising SPI5 I could not see any clock signal generated. I am using STM32H747-DISCO development board.
void MX_SPI5_Init(void)
{
hspi5.Instance = SPI5;
hspi5.Init.Mode = SPI_MODE_MASTER;
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
hspi5.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi5.Init.NSS = SPI_NSS_SOFT;
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi5.Init.TIMode = SPI_TIMODE_DISABLED;
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi5.Init.CRCPolynomial = 7;
hspi5.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi5.Init.NSSPMode = SPI_NSS_PULSE_ENABLED;
HAL_SPI_Init(&hspi5);
if(HAL_SPI_Init(&hspi5) != HAL_OK)
{
/* Initialization Error */
HAL_UART_Transmit(&huart3,(void *)"SPI_Init_error\r\n",18,100);
Error_Handler();
}
if(HAL_SPI_Init(&hspi5) == HAL_OK)
{
/* Initialization Error */
HAL_UART_Transmit(&huart3,(void *)"SPI_Init_success\r\n",18,100);
Error_Handler();
}
}
After the initialisation function is called, HAL_SPI_Init(&hspi5) sends HAL_OK and in terminal I can see SPI_Init_success message.
Accroding to the user manual of the development board, SPI_SCK is in D13 pin of CN5 connector. When I saw the pin in oscilloscope clock is not generated at all. Could you please let me know the thing that I am missing in this case and why the clock is not generated.
2021-05-20 07:23 AM
It should be : /* Enable SPI clock */
SPIx_CLK_ENABLE();
defined into the STM32H7xx_hal_msp.c and into the main.h you may add
#define SPIx_CLK_ENABLE() __HAL_RCC_SPI5_CLK_ENABLE()
since you are using SPI5
Hope that's help you to be able to see now your clock on SPI5_SCK
Br
2021-05-21 03:47 AM
I have followed all the things that you have mentioned but still I am not able to see anything. Now, I don't know the problem. Do you see any other problems ?
2021-05-21 09:21 AM
Basic question, Once you have initialized your SPI, do you fill the SPI transmit buffer with data ? The clock will be generated as soon as the transmit buffer is no more empty, as you are master on the bus. The only transmission I can see on the extracted code you put initially in the message was only some transmit ON UART.
2021-05-21 09:22 AM
Basic question, Once you have initialized your SPI, do you fill the SPI transmit buffer with data ? The clock will be generated as soon as the transmit buffer is no more empty, as you are master on the bus. The only transmission I can see on the extracted code you put initially in the message was only some transmit ON UART.
2021-05-23 11:44 PM
I have transmitted the data in while(1) loop after initialising the SPI bus. After debugging, I noticed one thing that the code is stuck in MX_SPI5_Init(); and it never goes to the while(1) loop. Do you know why is it stuck in this Init function and never goes to while(1) loop
#define data 0x40
while (1)
{
BSP_LED_On(0u);
//Turns CS high
CS_High();
HAL_SPI_Transmit(&hspi5, (uint8_t *)data,1,100);
CS_Low();
HAL_Delay(6000);
}
2021-05-24 03:10 AM
I fixed the code getting stuck in MX_SPIO_Init() but still am not getting any clock signal. Could you please help me out on this.
2021-05-25 05:21 AM
Hi,
Are you able to see with teh debugger, the TXC bit cleared when the tx buffer is filled ? Normally at the end of transfer (even if you can't not yet seen the clock outside), the TXC flag should rise again. (you set the breakpoint after the HAL_Delay...). In such case, it means that internally the master SPI is running. If it is the case, There is no reason explaining the clock absence if the GPIO is set correctly with the proper AF as already discussed, (Please check the GPIO configuration registers in debug mode as well, to be sure that the registers have been written properly with the configuration you retained). Last question :
Does the data is visible in output plugging as well a scope or even the data MOSI is not toggling ?
Are you OK with your NSS ? I saw that the NSS is managed by software in your case. Please check that the SSI bit is well at 1 -(in SPI2S_CR1) and SSM = 1 in order to consider the SPI as master and the internal NSS managed by the bit SSI (SSOE should be equal to 0).
And last, I don't think you need to enable hspi5.Init.NSSPMode = SPI_NSS_PULSE_ENABLED;
You can put DISABLED instead, but I suppose that there would be no Incidence due to that.
BR