UC GEE
UC GEE
DIIDevHeads IoT Integration Server
Created by Sterling on 7/11/2024 in #code-review
How can I resolve UART transmission errors on my STM32F407VGT6 MCU during rapid string transmission?
Yes @Sterling , you can further improve efficiency by using a more event-driven approach, such as implementing a queue for the strings you want to send and transmitting the next string in the callback function once the current transmission completes. This way, the MCU can perform other tasks while waiting for UART transmissions to complete. Here's an example modification:
uint8_t TxData[] = "test123\n";
int currentStringIndex = 0;
int totalStrings = 10;

void StartNextTransmission(void) {
if(currentStringIndex < totalStrings) {
if(HAL_UART_Transmit_IT(&huart3, TxData, strlen(TxData)) != HAL_OK) {
Error_Handler();
}
currentStringIndex++;
}
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
if(huart->Instance == USART3) {
StartNextTransmission();
}
}

int main(void) {
// Initial setup
StartNextTransmission();
while(1) {
// Other tasks can be performed here
}
}
uint8_t TxData[] = "test123\n";
int currentStringIndex = 0;
int totalStrings = 10;

void StartNextTransmission(void) {
if(currentStringIndex < totalStrings) {
if(HAL_UART_Transmit_IT(&huart3, TxData, strlen(TxData)) != HAL_OK) {
Error_Handler();
}
currentStringIndex++;
}
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
if(huart->Instance == USART3) {
StartNextTransmission();
}
}

int main(void) {
// Initial setup
StartNextTransmission();
while(1) {
// Other tasks can be performed here
}
}
In this approach, StartNextTransmission() is called in the main function to initiate the first transmission, and subsequent transmissions are triggered within the callback function.
7 replies