Skip to main content
Associate II
September 16, 2024
Solved

UART Transmitting issue or any other issue

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.

AHayee_0-1726491245079.png

Following is the logic analyzer waveform when Line no 29 and 30 are transmitted

AHayee_1-1726491391625.png

Kindly correct me where I am making mistake.

Thanks and best regards

This topic has been closed for replies.
AHayeeBest answer
Associate II
September 18, 2024

The issue is resolved after I added the following function

void SysTick_Handler(void){
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}

Thanks everyone for your support 

8 replies

waclawek.jan
Super User
September 16, 2024

Is there any error or warning during compilation?

JW

Andrew Neil
Super User
September 16, 2024

If you single-step those lines, does each one transmit?

Do any of the HAL_UART_Transmit() calls return an error?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
AHayeeAuthor
Associate II
September 16, 2024

@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?

Andrew Neil
Super User
September 16, 2024

@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!
 }

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
September 16, 2024

@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:

AndrewNeil_0-1726499161524.png

Are you sure that your connections are secure & reliable?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User
September 16, 2024

Try to transmit something also in the while() loop, e.g. the "Hello" string, in a loop.

JW

Karl Yamashita
Principal
September 16, 2024

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.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
AHayeeAuthorBest answer
Associate II
September 18, 2024

The issue is resolved after I added the following function

void SysTick_Handler(void){
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}

Thanks everyone for your support