Skip to main content
wjian.2
Associate III
August 21, 2023
Solved

Use variables values from main.c in another file

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

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
August 21, 2023

>> 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 (See Profile) Up vote any posts that you find helpful, it shows what's working..

4 replies

Tesla DeLorean
Guru
August 21, 2023

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
wjian.2
wjian.2Author
Associate III
August 21, 2023

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

 

 

 

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
August 21, 2023

>> 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 (See Profile) Up vote any posts that you find helpful, it shows what's working..