A code sample showing the use of the asynchronous Serial APIs.
Dependencies: mbed
Beware: this example is only compatible with boards supporting the asynchronous APIs!
Information
All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.
Diff: main.cpp
- Revision:
- 3:f911d11682f3
- Parent:
- 0:074157529cc4
- Child:
- 4:bbf422ee69e4
--- a/main.cpp Wed May 13 11:59:39 2015 +0000 +++ b/main.cpp Wed May 13 12:09:20 2015 +0000 @@ -50,12 +50,12 @@ LowPowerTicker blinker; bool blinking = false; event_callback_t serialEventCb; -DigitalOut LED; -char rx_buf[BUFF_LENGTH + 1]; +DigitalOut LED(LED_PIN); +uint8_t rx_buf[BUFF_LENGTH + 1]; /*------------------ Callbacks -------------------*/ void blink(void) { - LED = ~LED; + LED = !LED; } void serialCb(int events) { @@ -88,10 +88,10 @@ } // Echo string, no callback - test_connection.write(rx_buf, i+1, (event_callback_t*)0, 0); + test_connection.write(rx_buf, i+1, 0, 0); // Reset serial reception - test_connection.read(rx_buf, BUFF_LENGTH, &serialEventCb, SERIAL_EVENT_RX_ALL, 'S'); + test_connection.read(rx_buf, BUFF_LENGTH, serialEventCb, SERIAL_EVENT_RX_ALL, 'S'); } /*-------------------- Main ----------------------*/ @@ -102,7 +102,7 @@ /* Setup serial connection */ test_connection.baud(BRATE); test_connection.printf("Low Power API test\n\nSend 'S' to toggle blinking\n"); - test_connection.read(rx_buf, BUFF_LENGTH, &serialEventCb, SERIAL_EVENT_RX_ALL, 'S'); + test_connection.read(rx_buf, BUFF_LENGTH, serialEventCb, SERIAL_EVENT_RX_ALL, 'S'); /* Let the callbacks take care of everything */ while(1) sleep();