This is workaround to use I2C/SPI and serial together on BLE Nano.

Dependents:   SimpleSample

Committer:
coisme
Date:
Fri Aug 14 00:19:19 2015 +0000
Revision:
0:f3f4407ec133
Child:
1:312356f93678
First commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
coisme 0:f3f4407ec133 1 #ifndef SERIALNANO_H
coisme 0:f3f4407ec133 2 #define SERIALNANO_H
coisme 0:f3f4407ec133 3
coisme 0:f3f4407ec133 4 #include "Serial.h"
coisme 0:f3f4407ec133 5
coisme 0:f3f4407ec133 6 #if DEVICE_SERIAL
coisme 0:f3f4407ec133 7
coisme 0:f3f4407ec133 8 namespace mbed{
coisme 0:f3f4407ec133 9 /**
coisme 0:f3f4407ec133 10 * This is workaround to use I2C and serial together on BLE Nano.
coisme 0:f3f4407ec133 11 *
coisme 0:f3f4407ec133 12 * @code
coisme 0:f3f4407ec133 13 * #include "mbed.h"
coisme 0:f3f4407ec133 14 * #include "SerialNano.h"
coisme 0:f3f4407ec133 15 *
coisme 0:f3f4407ec133 16 * #define PIN_SERIAL_TX P0_28
coisme 0:f3f4407ec133 17 * #define PIN_SERIAL_RX P0_29
coisme 0:f3f4407ec133 18 *
coisme 0:f3f4407ec133 19 * #define I2C_SPEED_100KHZ 100000
coisme 0:f3f4407ec133 20 *
coisme 0:f3f4407ec133 21 * int main() {
coisme 0:f3f4407ec133 22 * // Initialize serial. This must be done before I2C initialization.
coisme 0:f3f4407ec133 23 * SerialNano serial(PIN_SERIAL_TX, PIN_SERIAL_RX);
coisme 0:f3f4407ec133 24 * serial.baud(115200);
coisme 0:f3f4407ec133 25 *
coisme 0:f3f4407ec133 26 * // Initialize I2C
coisme 0:f3f4407ec133 27 * I2C connection(I2C_SDA0, I2C_SCL0);
coisme 0:f3f4407ec133 28 * connection.frequency(I2C_SPEED_100KHZ);
coisme 0:f3f4407ec133 29 *
coisme 0:f3f4407ec133 30 * while (true) {
coisme 0:f3f4407ec133 31 * // some i2c work
coisme 0:f3f4407ec133 32 * // ...
coisme 0:f3f4407ec133 33 * serial.printf("I2C data\n");
coisme 0:f3f4407ec133 34 * wait_ms(500);
coisme 0:f3f4407ec133 35 * }
coisme 0:f3f4407ec133 36 * }
coisme 0:f3f4407ec133 37 * @endcode
coisme 0:f3f4407ec133 38 */
coisme 0:f3f4407ec133 39 class SerialNano : public Serial {
coisme 0:f3f4407ec133 40 public:
coisme 0:f3f4407ec133 41 SerialNano(PinName tx, PinName rx);
coisme 0:f3f4407ec133 42 };
coisme 0:f3f4407ec133 43
coisme 0:f3f4407ec133 44 } // namespace mbed
coisme 0:f3f4407ec133 45
coisme 0:f3f4407ec133 46 #endif // DEVICE_SERIAL
coisme 0:f3f4407ec133 47
coisme 0:f3f4407ec133 48 #endif // SERIALNANO_H