Arkadi Rafalovich
/
STM32_Print_PC-Xbee
xbee shield simple test code
main.cpp@1:2b7034eb3015, 2019-02-04 (annotated)
- Committer:
- Arkadi
- Date:
- Mon Feb 04 13:05:44 2019 +0000
- Revision:
- 1:2b7034eb3015
- Parent:
- 0:1b9c87e81f07
changed baud rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Arkadi | 0:1b9c87e81f07 | 1 | #include "mbed.h" |
Arkadi | 0:1b9c87e81f07 | 2 | |
Arkadi | 0:1b9c87e81f07 | 3 | /*------------------------------------------------------------------------------ |
Arkadi | 0:1b9c87e81f07 | 4 | Before to use this example, ensure that you an hyperterminal installed on your |
Arkadi | 0:1b9c87e81f07 | 5 | computer. More info here: https://developer.mbed.org/handbook/Terminals |
Arkadi | 0:1b9c87e81f07 | 6 | |
Arkadi | 0:1b9c87e81f07 | 7 | The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their |
Arkadi | 0:1b9c87e81f07 | 8 | definition in the PinNames.h file). |
Arkadi | 0:1b9c87e81f07 | 9 | |
Arkadi | 0:1b9c87e81f07 | 10 | The default serial configuration in this case is 9600 bauds, 8-bit data, no parity |
Arkadi | 0:1b9c87e81f07 | 11 | |
Arkadi | 0:1b9c87e81f07 | 12 | If you want to change the baudrate for example, you have to redeclare the |
Arkadi | 0:1b9c87e81f07 | 13 | serial object in your code: |
Arkadi | 0:1b9c87e81f07 | 14 | |
Arkadi | 0:1b9c87e81f07 | 15 | Serial pc(SERIAL_TX, SERIAL_RX); |
Arkadi | 0:1b9c87e81f07 | 16 | |
Arkadi | 0:1b9c87e81f07 | 17 | Then, you can modify the baudrate and print like this: |
Arkadi | 0:1b9c87e81f07 | 18 | |
Arkadi | 0:1b9c87e81f07 | 19 | pc.baud(115200); |
Arkadi | 0:1b9c87e81f07 | 20 | pc.printf("Hello World !\n"); |
Arkadi | 0:1b9c87e81f07 | 21 | ------------------------------------------------------------------------------*/ |
Arkadi | 0:1b9c87e81f07 | 22 | |
Arkadi | 0:1b9c87e81f07 | 23 | DigitalOut led(LED1); |
Arkadi | 0:1b9c87e81f07 | 24 | |
Arkadi | 0:1b9c87e81f07 | 25 | Serial pc(SERIAL_TX, SERIAL_RX); |
Arkadi | 0:1b9c87e81f07 | 26 | Serial xbee(PA_9, PA_10); |
Arkadi | 0:1b9c87e81f07 | 27 | |
Arkadi | 0:1b9c87e81f07 | 28 | int main() |
Arkadi | 0:1b9c87e81f07 | 29 | { |
Arkadi | 1:2b7034eb3015 | 30 | pc.baud(9600); |
Arkadi | 1:2b7034eb3015 | 31 | xbee.baud(9600); |
Arkadi | 0:1b9c87e81f07 | 32 | int i = 1; |
Arkadi | 0:1b9c87e81f07 | 33 | |
Arkadi | 0:1b9c87e81f07 | 34 | pc.printf("Hello World pc!\r\n"); |
Arkadi | 0:1b9c87e81f07 | 35 | xbee.printf("Hello World Xbee!\r\n"); |
Arkadi | 0:1b9c87e81f07 | 36 | |
Arkadi | 0:1b9c87e81f07 | 37 | while(1) { |
Arkadi | 0:1b9c87e81f07 | 38 | wait(1); // 1 second |
Arkadi | 0:1b9c87e81f07 | 39 | led = !led; // Toggle LED |
Arkadi | 0:1b9c87e81f07 | 40 | pc.printf("PC - This program runs since %d seconds.\r\n", i++); |
Arkadi | 0:1b9c87e81f07 | 41 | xbee.printf("Xbee - This program runs since %d seconds.\r\n", i++); |
Arkadi | 0:1b9c87e81f07 | 42 | } |
Arkadi | 0:1b9c87e81f07 | 43 | } |