Showing results for 
Search instead for 
Did you mean: 

Data transmission is not happening using SPI ?

Associate II

Hi Team,

I am using the STM32H745ZI-Q nucleo board . I am Trying to Transmit the data through the SPI using LL.

Here I am using one nucleo board cm7 for transmition and I am using another same model nucleo board cm7 for the receiving.

In the transmition side I am using the SPI1. I am unable to trasmit the data. Ia m attaching my code below . Please check and let me know if any modifications needed.

Below is SPI master code.

/* Includes ------------------------------------------------------------------*/

#include "main.h"

uint32_t timeout = 0;

/* SPI Init Structure */

LL_SPI_InitTypeDef  SPI_InitStruct;

LL_GPIO_InitTypeDef GPIO_InitStruct;

uint8_t  TxBuffer[] = Welcome_master_slave_SPI;

uint32_t  TransmitIndex = 0;

void SystemClock_Config(void);

void Error_Handler(void);

static void MX_GPIO_Init(void);

static void MX_SPI1_Init(void);

static void GPIOPins_SPI1_Config(void);

void SPI_TransferError_Callback(void);

void SPI1_EOT_Callback(void);

void SPI1_Tx_Callback(void);

int main(void)


 timeout = 0xFF;

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */


 /* System interrupt init*/







 while (1)


   LL_SPI_TransmitData8(SPI1, TxBuffer[TransmitIndex]);



void SystemClock_Config(void)



 while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)






  /* Wait till HSE is ready */

 while(LL_RCC_HSE_IsReady() != 1)














  /* Wait till PLL is ready */

 while(LL_RCC_PLL1_IsReady() != 1)



  /* Intermediate AHB prescaler 2 when target frequency clock is higher than 80 MHz */



  /* Wait till System clock is ready */













static void GPIOPins_SPI1_Config(void)


 /* (1) Enables GPIO clock and configures the SPI1 pins *******************/

 /* Enable the peripheral clock of GPIOA */


 /* SPI1 SCK GPIO pin configuration*/

 GPIO_InitStruct.Pin    = LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;


 GPIO_InitStruct.Pull   = LL_GPIO_PULL_DOWN;

 GPIO_InitStruct.Speed   = LL_GPIO_SPEED_HIGH;

 GPIO_InitStruct.Alternate = LL_GPIO_AF_5;

 LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* (2) Configure NVIC for SPI1 transfer complete/error interrupts **********/

 /* Set priority for SPI1_IRQn */

 NVIC_SetPriority(SPI1_IRQn, 0);

 /* Enable SPI1_IRQn */



static void MX_SPI1_Init(void)


 /* Configure SPI MASTER ****************************************************/

 /* Enable SPI1 Clock */


 /* Configure the SPI1 parameters */


 SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;

 SPI_InitStruct.ClockPhase    = LL_SPI_PHASE_2EDGE;

 SPI_InitStruct.ClockPolarity   = LL_SPI_POLARITY_HIGH;

 SPI_InitStruct.BitOrder     = LL_SPI_MSB_FIRST;

 SPI_InitStruct.DataWidth     = LL_SPI_DATAWIDTH_8BIT;

 SPI_InitStruct.NSS        = LL_SPI_NSS_SOFT;


 SPI_InitStruct.Mode       = LL_SPI_MODE_MASTER;

 LL_SPI_Init(SPI1, &SPI_InitStruct);









static void MX_GPIO_Init(void)


 LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* GPIO Ports Clock Enable */









 LL_GPIO_ResetOutputPin(GPIOE, LL_GPIO_PIN_1);


 GPIO_InitStruct.Pin = LL_GPIO_PIN_13;


 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

 LL_GPIO_Init(GPIOC, &GPIO_InitStruct);


 GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_14;




 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

 LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = LL_GPIO_PIN_1;




 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

 LL_GPIO_Init(GPIOE, &GPIO_InitStruct);


void SPI1_IRQHandler(void)



 /* Check OVR/UDR flag value in ISR register */

 if(LL_SPI_IsActiveFlag_OVR(SPI1) || LL_SPI_IsActiveFlag_UDR(SPI1)) {

 /* Call Error function */



 /* Check TXP flag value in ISR register */

 if((LL_SPI_IsActiveFlag_TXP(SPI1) && LL_SPI_IsEnabledIT_TXP(SPI1))) {

 /* Call function Reception Callback */




 /* Check EOT flag value in ISR register */

 if(LL_SPI_IsActiveFlag_EOT(SPI1) && LL_SPI_IsEnabledIT_EOT(SPI1)) {

 /* Call function Reception Callback */





void SPI1_Tx_Callback(void)


 /* Write character in Data register.

  * TXP flag is cleared by filling data into TXDR register */



 if(sizeof(TxBuffer) == TransmitIndex) {

 TransmitIndex = 0;



Andrew Neil
Evangelist III

"I am unable to trasmit the data"

How do you know it's a failure to transmit?

Perhaps the failure is in receiving?

Or both?

Have you carefully checked the hardware connections?

Have you used an oscilloscope or analyser to see what's actually happening on the wires?


Associate II

Hi @Andrew Neil​ 

I checked with the receive first But I am not getting Then After I checked with the transmit .. When the transmission is happened it should come to call back ... but it is not coming sometimes it is coming to call back sometimes it not.

I am attaching the receiving code below Please check with the above transmit code and let me know any changes needed.

Please help me out in this . If you have any LL spi code snippet and send it to me that would be great.

Thank you.

Associate II

Hi Team,

Please share the LL_SPI working code base for stm32h745zi-Q

Or Else

Please give me input for my next step by refer the above code.

Thank you .

Hi @Andrew Neil​ 

In the Above code In MX_SPI1_Init(); function when I am enabling the interrupts its directly going in to the call back function and increasing the index value based on the code in the call back function , and after all the interrupts enable the index value become 16.

and when coming to main function of transmit line it is transmitting 16th character of the tx buff and it is coming out from that loop... It is transmitting only on character.

why the index value becoming 16 while enabling the interrupts and why it is only transmitting one character.. could you please help me to sort out this.