cancel
Showing results for 
Search instead for 
Did you mean: 

Use variables values from main.c in another file

wjian.2
Associate II

if i use static UART_HandleTypeDef huart8; in main.c . when i want to run it in fpvisionai.c  HAL_UART_Transmit(&huart8,etc) say huart8 undeclared , should i use include <main.h> in this file,o how to set UART_HandleTypeDef huart8 as global variable

1 ACCEPTED SOLUTION

Accepted Solutions

>> should be fp_vision_app.h? 

It NEEDS to be in something that's INCLUDED, could be main.h, or a file both share, or you put extern UART_HandleTypeDef huart8; in the .C file you're using it from, provided you've also defined what UART_HandleTypeDef is

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

Using "static" means its not visible outside of main.c

Use this in main.h

extern UART_HandleTypeDef huart8;

And this in main.c

UART_HandleTypeDef huart8;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

still have this trouble fp_vision_app.c:280:25: error: 'huart8' undeclared (first use in this function), should be fp_vision_app.h? 

wjian2_0-1692639337342.png

wjian2_0-1692640115437.png

wjian2_1-1692640149648.png

 

 

 

>> should be fp_vision_app.h? 

It NEEDS to be in something that's INCLUDED, could be main.h, or a file both share, or you put extern UART_HandleTypeDef huart8; in the .C file you're using it from, provided you've also defined what UART_HandleTypeDef is

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

means   Use this in main.h

"extern UART_HandleTypeDef huart8;"

And this in main.c

UART_HandleTypeDef huart8;

and in the fp_vision_app.c

include ''main.h" no ?