Skip to main content
vbk22398
Senior
Apr 25, 2024 9:55 AM UTC
Question

SPI_Receiving data is improper because of HAL Functions

I am sending multiple bytes in spi protocol. The sender is sending properly through AARDWARK(Total Phase Control)Software. But only the odd number of bytes are received and the receiving is not proper using these HAL_Functions. What is the issue?

int main(void) {

SystemClock_Config();

MX_GPIO_Init();

MX_SPI3_Init();

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_SET);

 

/*

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);

HAL_SPI_TransmitReceive(&hspi3, data_tra, data_rec, 5, HAL_MAX_DELAY);

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_SET);

*/

/*

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);

HAL_SPI_TransmitReceive_IT(&hspi3, data_tra, data_rec, 3);

HAL_Delay(1);

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_SET);

*/

 

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);

HAL_SPI_Transmit(&hspi3, data_tra, 3, HAL_MAX_DELAY);

HAL_SPI_Receive(&hspi3, data_rec, 3, HAL_MAX_DELAY);

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_SET);

while (1) {

}

}



The above works fine with the following code.


HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);

HAL_SPI_Transmit(&hspi3, data_tra, 3, HAL_MAX_DELAY);

for(int i=0;i<3;i++)

{

HAL_SPI_Receive(&hspi3, &data_rec[i], 1, HAL_MAX_DELAY);

}

HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_SET);

i want to know the difference between
HAL_SPI_Transmit
HAL_SPI_TransmitReceive_IT
HAL_SPI_TransmitReceive

This topic has been closed for replies.

1 reply

unsigned_char_array
Lead III
Apr 25, 2024 11:26 AM UTC

Please use a code block in your post. It is hard to read like this.

You can find the option here:

unsigned_char_array_0-1714395237827.png

 

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."