cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_transmit in other fils (no main.c)

jlecl.1
Associate III

Hello,

I'm trying to send data over uart from a another file.

My main :

UART_HandleTypeDef huart1;
DMA_HandleTypeDef hdma_usart1_tx;
 
int main(void)
{
     MX_USART1_UART_Init();
 
     While(1)
     {
     }
}

My error is :

../Core/Src/AT_Command.c:22:21: error: 'huart1' undeclared (first use in this function)

I'have read that a must declare "UART_HandleTypeDef" as extern...

but i'no unsterdant how.

do you have more information ?

1 ACCEPTED SOLUTION

Accepted Solutions
Winfred LU
ST Employee

Declaring it (the global variable) extern is required

because the variable is declared in another file (that can be accessed) in the program.

They are in different scope.

View solution in original post

2 REPLIES 2
Winfred LU
ST Employee

Declaring it (the global variable) extern is required

because the variable is declared in another file (that can be accessed) in the program.

They are in different scope.

jlecl.1
Associate III

Ok, i have found !

So in your main

extern UART_HandleTypeDef huart1;

instead of "UART_HandleTypeDef huart1; "

AND in your other file, add

UART_HandleTypeDef huart1;