2024-02-21 09:13 PM - edited 2024-02-21 09:15 PM
I am developing using the STM32H series, but LL_SPI_IsActiveFlag_EOT does not go high during spi4 communication. And The Nss pin and reset pin are well controlled, but mosi and spi clock do not work.
This is my code. please help me.
// spi set
void MX_SPI4_Init(void)
{
/* USER CODE BEGIN SPI4_Init 0 */
/* USER CODE END SPI4_Init 0 */
LL_SPI_InitType
Def SPI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI4;
PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_D2PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI4);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOE);
/**SPI4 GPIO Configuration
PE14 ------> SPI4_MOSI
PE12 ------> SPI4_SCK
PE13 ------> SPI4_MISO
*/
GPIO_InitStruct.Pin = SPI_MOSI_Pin|SPI_SCK_Pin|SPI_MISO_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
LL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* USER CODE BEGIN SPI4_Init 1 */
/* USER CODE END SPI4_Init 1 */
/* SPI4 parameter configuration*/
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.CRCPoly = 0;
LL_SPI_Init(SPI4, &SPI_InitStruct);
LL_SPI_SetStandard(SPI4, LL_SPI_PROTOCOL_MOTOROLA);
LL_SPI_SetCRCWidth(SPI4, 0x00000000UL); // ?
LL_SPI_DisableNSSPulseMgt(SPI4);
/* USER CODE BEGIN SPI4_Init 2 */
/* USER CODE END SPI4_Init 2 */
}
// main.c
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SPI4_Init();
LL_SPI_SetTransferSize(SPI4, 4);
LL_SPI_StartMasterTransfer(SPI4);
LL_SPI_Enable(SPI4);
LL_SPI_SetFIFOThreshold(GP22_SPI, LL_SPI_FIFO_TH_04DATA);
Spi_Reset();
Spi_wr_Opcode(0x50);
while (1)
{
}
}
// Spi_Reset();
void Spi_Reset(void)
{
LL_GPIO_ResetOutputPin(SPI_RSTN_GPIO_Port, SPI_RSTN_Pin);
LL_mDelay(1);
LL_GPIO_SetOutputPin(SPI_RSTN_GPIO_Port, SPI_RSTN_Pin);
LL_mDelay(500);
}
//Spi_wr_Opcode(uint8_t opcode_byte);
void Spi_wr_Opcode(uint8_t opcode_byte) // POWER ON RESET 0x50
{
LL_SPI_SetTransferDirection(SPI4, LL_SPI_HALF_DUPLEX_TX);
NSS_ON;
while (!LL_SPI_IsActiveFlag_TXP(SPI4));
LL_SPI_TransmitData8(SPI4, opcode_byte);
while (!LL_SPI_IsActiveFlag_TXP(SPI4));
while (!LL_SPI_IsActiveFlag_EOT(SPI4));
NSS_OFF;
}
To be precise, it is not possible to escape from the while (!LL_SPI_IsActiveFlag_EOT(SPI4)); of the Spi_wr_Opcode function.
Also, spi clock and mosi are not displayed.
2024-02-22 01:54 AM
Hello @ToonToon ,
You can check and compare your code with LL SPI example available within STM32CubeH7 MCU package.
I advise you to read this AN5543 and the STM32H7 errata in SPI section to check if the limitation is part of your issue.
2024-02-22 06:38 AM
Need to set TSIZE if you want the EOT flag to work.