Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 5 months ago.
How to access a declared Usart1 from another cpp file ?
I guess that I must place an extern declaration in the new.cpp file,
but I cant find any syntax that shows me how to do it :(
1 Answer
8 years, 5 months ago.
file1:
Serial pc(USB_TX,USB_RX);
file 2:
extern Serial pc;
Or you can put the extern command in a header file that you then include in everything. For a single serial port this isn't worth it but if you have lots of variables or objects you want to be visible in two files then it makes things easier. globals.h:
extern Serial pc;
file1.cpp:
#include "globals.h" Serial pc(USB_TX,USB_RX);
file2.cpp:
#include "globals.h"