Turn from: Sina @walkant
Part Four serial interface UART and console
Detailed reference: http://dev.ardupilot.com/wiki/learning-ardupilot-uarts-and-the-console/
UART is very important for debugging output, digital transmission, GPS module and so on.
1, 5 UART
A total of 5 UART are defined, and their uses are:
- The uarta– serial terminal, usually a micro USB interface, runs the Mavlink protocol.
- UARTB–GPS1 module.
- uartc– the main number of interfaces, that is, Pixhawk telem1 interface.
- uartd– frequency interface, that is, TELEM2 interface.
- UARTE–GPS2 module.
Some UART have a dual role, for example, by modifying the serial2_protocol parameter, you can change the UARTD mavlink telemetry number to FRSky telemetry digital transmission (Jiangsu, China).
Test the example sketch in the Libraries/ap_hal/examples/uart_test directory and output a hello message for each of the 5 UART. Using the USB to serial port tool, you can test.
2. Debug the Terminal Debug console
As a supplement to the 5 UART, some platforms also have an additional debug console debug terminal. You can judge by examining the Hal_os_posix_io macro definition, such as:
#if Hal_os_posix_io
::p rintf ("Hello console\n");
#endif
If you have defined hal_os_posix_io, you can try to view the Ap_hal/ap_hal_boards.h code.
3. UART function
Each UART has a series of basic operating functions, mainly:
1. printf–formatted Print
2. printf_p–formatted print with Progmem string (saves memory on AVR boards)
3. Println–print and line feed
4. Write–write a bunch of bytes
5. Read–read some bytes
6. Available–check if any bytes is waiting
7. Txspace–check How much outgoing buffer space is available
8. Get_flow_control–check if the UART has flow control capabilities
You can view their definitions in Ap_hal and test them with uart_test.
4. UART Interface Description
Many UART interface, many names, their correspondence, I summarize the following, if there is a problem, please email to [email protected] Sina @walkant, welcome correction.
Code Definition |
PCB Circuit Representation |
Flight Control Board Interface |
Serial Marking |
Description |
The description in APM code |
Representation on a circuit board |
Identification on the Pixhawk housing |
Serial number |
|
Uarta |
Micro USB |
Usb |
Usb |
USB connection, Support Mavlink protocol |
Uartb |
UART4 |
Gps |
Serial 3 |
Connect the GPS module to the other CAN2 interface |
Uartc |
UART2 |
Telem1 |
Serial 1 |
Connect the 1th Digital transmission module |
Uartd |
UART3 |
Telem2 |
Serial 2 |
Connect the 2nd Digital transmission module |
Uarte |
UART8 |
Serial4/5 |
Serial 4 |
General Connection GPS2 Module |
/ |
UART7 |
Serial4/5 |
Serial 5 |
Debug Console for program debugging |
Previous article:
Pixhawk Source Note One: APM code basic structure: http://blog.sina.com.cn/s/blog_402c071e0102v59r.html
Pixhawk Source Note two: APM Thread: http://blog.sina.com.cn/s/blog_402c071e0102v5br.html
The UART Test code: LIBRARIES/AP_HAL/EXAMPLES/UART_TEST) is tested in detail:
void loop (void)
{
Micro USB port output : Hello on UART uarta at 764.461 seconds
Test_uart (Hal.uarta, "Uarta");
GPS Interface Output :Hello on UART uartb at 91.845 seconds
Test_uart (HAL.UARTB, "UARTB");
Digital Telem1 output :Hello on UART uartc at 24.693 seconds
Test_uart (HAL.UARTC, "UARTC");
Digital Telem2 output :Hello on UART uartd at 805.557 seconds
Test_uart (HAL.UARTD, "UARTD");
seiral 4 Port output :Hello on UART uarte at 911.812 seconds
Test_uart (Hal.uarte, "Uarte");
Also do-a raw printf () on some platforms, which prints to the
Debug console
#if Hal_os_posix_io
seiral 5 Port output: Hello on debug console at 976.857 seconds
::p rintf ("Hello on debug console at%.3f seconds\n", Hal.scheduler->millis () *0.001f);
#endif
Hal.scheduler->delay (1000);
}
SERIAL 5 As an important debug port. A large amount of information is output through this interface when the Pixhawk is started and can be used to monitor the boot process.
Reprint: Pixhawk Source note three: Serial interface UART and console