cancel
Showing results for 
Search instead for 
Did you mean: 

UART Transmitting issue or any other issue

AHayee
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
AHayee
Associate II

The issue is resolved after I added the following function

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

Thanks everyone for your support 

View solution in original post

8 REPLIES 8

Is there any error or warning during compilation?

JW

Andrew Neil
Evangelist III

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

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

AHayee
Associate II

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


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

 

 

Andrew Neil
Evangelist III

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

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

JW

Karl Yamashita
Lead III

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 smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.
AHayee
Associate II

The issue is resolved after I added the following function

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

Thanks everyone for your support