Skip to content

Instantly share code, notes, and snippets.

@pilotak
Created June 5, 2018 14:48
Show Gist options
  • Save pilotak/84c91b62d1d3e240f8bcb66e76e1dee1 to your computer and use it in GitHub Desktop.
Save pilotak/84c91b62d1d3e240f8bcb66e76e1dee1 to your computer and use it in GitHub Desktop.
#include "mbed.h"
#if DEVICE_SERIAL_ASYNCH
Serial pc(USBTX, USBRX);
#else
#error "Platform not compatible with Serial async"
#endif
#define BUFF_LENGTH 5
uint8_t rx_buf[BUFF_LENGTH];
void serialCb(int events) {
if (events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
} else if (events & SERIAL_EVENT_RX_COMPLETE) {
pc.printf("received data: \n");
for (int i = 0; i < BUFF_LENGTH; ++i) {
pc.printf("%c", rx_buf[i]);
}
pc.printf("\n");
} else {
pc.printf("Error\n");
}
pc.read(rx_buf, BUFF_LENGTH, event_callback_t(serialCb), SERIAL_EVENT_RX_ALL);
}
int main() {
pc.printf("Async serial example\n");
pc.read(rx_buf, BUFF_LENGTH, event_callback_t(serialCb), SERIAL_EVENT_RX_ALL);
while (1) {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment