|
| 1 | +/* |
| 2 | +// This file is subject to the terms and conditions defined in |
| 3 | +// file 'LICENSE.md', which is part of this source code package. |
| 4 | +*/ |
| 5 | + |
| 6 | +/* |
| 7 | +
|
| 8 | + The Apollo3 contains two UART peripherals that can be used with |
| 9 | + the Arduino Serial api. |
| 10 | + https://www.arduino.cc/reference/en/language/functions/communication/serial/ |
| 11 | + |
| 12 | + It is possible to route each UART instance (0 or 1) to a number of |
| 13 | + different pads of the Apollo3. Check the datasheet for all possible |
| 14 | + mappings. |
| 15 | + https://cdn.sparkfun.com/assets/learn_tutorials/9/0/9/Apollo3_Blue_MCU_Data_Sheet_v0_9_1.pdf |
| 16 | + Table 559 |
| 17 | + |
| 18 | + You can create new UART objects (which inherit from the HardwareSerial |
| 19 | + class in Arduino) by specifying the TX and RX pins, and optionally the |
| 20 | + RTS and CTS pins to enable flow control. Here are the constructor protorypes: |
| 21 | + UART(PinName tx, PinName rx, PinName rts, PinName cts); |
| 22 | + UART(pin_size_t tx, pin_size_t rx, pin_size_t rts, pin_size_t cts); |
| 23 | + |
| 24 | + It is possible to use either the mbed style PinName enumerations or the |
| 25 | + Arduino style pin_size_t pin numbers to specify pins. Either case will |
| 26 | + will determine the actuall Apollo3 pad according to the rules explained |
| 27 | + in the DigitalGPIO example. |
| 28 | +
|
| 29 | +*/ |
| 30 | + |
| 31 | +/* |
| 32 | + uart0 | | uart1 |
| 33 | +--------------------------------------------- |
| 34 | + tx | rx | rts | cts | | tx | rx | rts | cts |
| 35 | +---- ---- ----- ----- - ---- ---- ----- ----- |
| 36 | + 1 2 3 4 | | 8 2 10 11 |
| 37 | + 7 11 5 6 | | 10 4 16 17 |
| 38 | + 16 17 13 12 | | 12 9 20 21 |
| 39 | + 20 21 18 24 | | 14 13 30 26 |
| 40 | + 22 23 34 29 | | 18 15 31 29 |
| 41 | + 26 27 35 33 | | 20 19 34 32 |
| 42 | + 28 29 37 36 | | 24 21 41 36 |
| 43 | + 30 31 41 38 | | 35 25 44 45 |
| 44 | + 39 34 | | 37 36 |
| 45 | + 41 40 | | 39 38 |
| 46 | + 44 45 | | 42 40 |
| 47 | + 48 49 | | 46 43 |
| 48 | + | | 47 |
| 49 | +*/ |
| 50 | + |
| 51 | +//// uncomment to use these names if defined for your board |
| 52 | +//// (these are also the pins used for Serial1, which is |
| 53 | +//// available on applicable boards) |
| 54 | +//#define HAS_SERIAL1 |
| 55 | +//UART mySerial(SERIAL1_TX, SERIAL1_RX); |
| 56 | + |
| 57 | +#define BAUD 115200 // any number, common choices: 9600, 115200, 230400, 921600 |
| 58 | +#define CONFIG SERIAL_8N1 // a config value from HardwareSerial.h (defaults to SERIAL_8N1) |
| 59 | + |
| 60 | +void setup() { |
| 61 | + Serial.begin(BAUD); // set the baud rate with the begin() method |
| 62 | + Serial.println("Apollo3 = Serial"); |
| 63 | + Serial.println("Echo Back Character"); |
| 64 | + |
| 65 | + |
| 66 | +#ifdef HAS_SERIAL1 |
| 67 | + mySerial.begin(BAUD, CONFIG); // specify the config setting as the secnd argument |
| 68 | + mySerial.println("Apollo3 = mySerial"); |
| 69 | + mySerial.println("Echo Back Character"); |
| 70 | +#endif |
| 71 | +} |
| 72 | + |
| 73 | +void loop() { |
| 74 | + while(Serial.available()){ |
| 75 | + Serial.write(Serial.read()); |
| 76 | + } |
| 77 | + |
| 78 | +#ifdef HAS_SERIAL1 |
| 79 | + while(mySerial.available()){ |
| 80 | + mySerial.write(mySerial.read()); |
| 81 | + } |
| 82 | +#endif |
| 83 | +} |
0 commit comments