Associate II
November 2, 2022
Solved
STM32f1xx UART slow and when I added another logic it just didn't works
- November 2, 2022
- 2 replies
- 1663 views
I made a simple program on an ESP32 to send dummy data with something like this
$DUMMYDATA,0,1I've tried using another ESP32 as a receiver and it works perfectly. My goals is implement the same thing to my STM32F103C8T6. Here's my code for the first attempt.
while (1)
{
HAL_UART_Receive(&huart2, receivedData, sizeof(receivedData), 100);
CDC_Transmit_FS((uint8_t *)receivedData, strlen(receivedData));
}It works but the data is corrupted
⸮0kTԽ⸮5⸮⸮c 8 ⸮⸮ d⸮֩⸮&⸮⸮.⸮Z⸮�?|!Qi;⸮1⸮⸮z\⸮9⸮$DUMMYDATA,1,0Then I changed the third line to something like this
HAL_UART_Receive(&huart2, receivedData, sizeof(receivedData), HAL_MAX_DELAY);Now it works perfectly but with downside it just became really slow. Then I tried to add a simple logic to parse the data
while (1)
{
HAL_UART_Receive(&huart2, receivedData, sizeof(receivedData), HAL_MAX_DELAY);
strcpy(dataMode, strtok(receivedData, ','));
strcpy(latitude, strtok(NULL, ','));
strcpy(longitude, strtok(NULL, ','));
CDC_Transmit_FS((uint8_t *)dataMode, strlen(dataMode));
CDC_Transmit_FS((uint8_t *)latitude, strlen(latitude));
CDC_Transmit_FS((uint8_t *)longitude, strlen(longitude));
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}And now my STM didn't output anything at all. My questions are
- How can I tweak my receiver to receive data faster but still accurate enough?
- Why it just didn't do anything at all after I added another logic?
I've attached my project if its useful. Thanks in advance!