SPI_multiple_bytes_transfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-23 2:01 AM
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?check the following logic and help me if you could
int main(void) {
SystemClock_Config();
MX_GPIO_Init();
MX_SPI3_Init();
MX_LPUART1_UART_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) {
}
}
Solved! Go to Solution.
- Labels:
-
STM32L4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-25 4:25 AM
Speed is the issue. I was transfering the data at 2000kbps and the receiver also at the same speed. Since i reduced it to some 500kbps, it is working properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-23 8:58 AM
SPI has several configuration modes. Check that you're using the correct one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-23 11:33 PM
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
the values received in the above 3 places are different from each other
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-25 4:25 AM
Speed is the issue. I was transfering the data at 2000kbps and the receiver also at the same speed. Since i reduced it to some 500kbps, it is working properly.
