Skip to main content
jlecl.1
Associate III
June 5, 2023
Solved

HAL_transmit in other fils (no main.c)

  • June 5, 2023
  • 2 replies
  • 1542 views

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 ?

    This topic has been closed for replies.
    Best answer by Winfred LU

    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.

    2 replies

    Winfred LU
    Winfred LUBest answer
    ST Employee
    June 6, 2023

    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
    jlecl.1Author
    Associate III
    June 6, 2023

    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;