2024-09-16 05:58 AM - last edited on 2024-09-16 08:20 AM by SofLit
Hi Everyone,
I am using STM32F407DISCO board and made a simple program which transmit some values. The program is as follows
#include "stm32f4xx_hal.h"
#include "main.h"
UART_HandleTypeDef USART2Config;
void GPIO_Init(void);
void UART2_Init(void);
void Err_Handle(void);
char data[] = "Hello";
uint8_t value = 43;
uint16_t value2 = 1024;
char buffer[10];
int main(){
HAL_Init();
GPIO_Init();
UART2_Init();
HAL_GPIO_WritePin(GPIOD, RED_LED, 1);
HAL_GPIO_WritePin(GPIOD, GREEN_LED, 1);
HAL_GPIO_WritePin(GPIOD, ORANGE_LED, 1);
HAL_GPIO_WritePin(GPIOD, BLUE_LED, 1);
HAL_UART_Transmit(&USART2Config, (uint8_t*) data, strlen (data), HAL_MAX_DELAY);
HAL_UART_Transmit(&USART2Config, &value, 1, HAL_MAX_DELAY);
HAL_UART_Transmit(&USART2Config, (uint8_t*) &value2, sizeof(value2), HAL_MAX_DELAY);
while(1){
}
}
The code above only Transmit line 28 and 29, Line 30 not transmitted.
but when I comment out Line 28 then line 29 and 30 transmitted.
What I am doing wrong here?
Following is the logic analyzer waveform when Line no 28,29 and 30 are transmitted.
Following is the logic analyzer waveform when Line no 29 and 30 are transmitted
Kindly correct me where I am making mistake.
Thanks and best regards
Solved! Go to Solution.
2024-09-17 10:04 PM
The issue is resolved after I added the following function
void SysTick_Handler(void){
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
Thanks everyone for your support
2024-09-16 06:28 AM
Is there any error or warning during compilation?
JW
2024-09-16 06:45 AM
If you single-step those lines, does each one transmit?
Do any of the HAL_UART_Transmit() calls return an error?
2024-09-16 07:30 AM
@waclawek.jan No there is no error or warning while compilation
@Andrew Neil No I didn't check the single-step nor I checked if any error is returning.
How do I check if it is returning any error or not?
2024-09-16 07:40 AM
@AHayee wrote:How do I check if it is returning any error or not?
The same way you'd check the return value from any function call:
HAL_StatusTypeDef result;
:
:
result = HAL_UART_Transmit( &USART2Config, (uint8_t*) data, strlen (data), HAL_MAX_DELAY );
if( result != HAL_OK )
{
// An error occured!
}
2024-09-16 08:06 AM - edited 2024-09-16 08:07 AM
@AHayee wrote:I am using STM32F407DISCO board
How are you connecting to the UART?
This board requires you to make the connection manually from the UART to the ST-Link's VCP:
Are you sure that your connections are secure & reliable?
2024-09-16 08:10 AM
Try to transmit something also in the while() loop, e.g. the "Hello" string, in a loop.
JW
2024-09-16 03:12 PM
Looks like you're re-inventing the wheel
UART_HandleTypeDef USART2Config;
Show your configuration.
And where is you System Clock configuration? Are you relying on HSI?
What is APB1 set as?
Better yet, upload your IOC file.
2024-09-17 10:04 PM
The issue is resolved after I added the following function
void SysTick_Handler(void){
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
Thanks everyone for your support