From: Andy Spencer Date: Mon, 3 Mar 2014 21:34:03 +0000 (+0000) Subject: Add UART 1/2 testing X-Git-Url: http://pileus.org/git/?p=~andy%2Fcsm213a-hw;a=commitdiff_plain;h=d5a9226714d158f2ac458425eba2550fd02c5cbe Add UART 1/2 testing --- diff --git a/hw2/main.cpp b/hw2/main.cpp index 436f750..aac88f2 100644 --- a/hw2/main.cpp +++ b/hw2/main.cpp @@ -99,7 +99,7 @@ void serial_send_sync(void) /** * Output external event received message * event: id of the received event - * time: compensated timestamp of the event + * time: compensated timestamp of the event */ void serial_send_event(uint16_t event, ntime_t *time) { @@ -116,17 +116,50 @@ void serial_receive(void) * Data definitions * ********************/ +// LEDs DigitalOut led1(LED1); DigitalOut led2(LED2); +// UARTs tx rx +Serial uart0(USBTX, USBRX); +Serial uart1(PTE0, PTE1); +Serial uart2(PTE16, PTE17); + /******** * Main * ********/ +void test_uart(void) +{ + char xmt[32] = "hello, world"; + char rcv[32] = {}; + + printf("start\r\n"); + for (int i = 0; xmt[i]; i++) { + uart1.putc(xmt[i]); + rcv[i] = uart2.getc(); + } + printf("xmt: %s\r\n", xmt); + printf("rcv: %s\r\n", rcv); +} + +void test_leds(void) +{ + led1 = 1; led2 = 0; wait(0.1); + led1 = 0; led2 = 1; wait(0.1); +} + int main(int argc, char **argv) { - while (1) { - led1 = 1; led2 = 0; wait(0.1); - led1 = 0; led2 = 1; wait(0.1); - } + uart0.baud(115200); + uart1.baud(115200); + uart2.baud(115200); + + test_uart(); + test_leds(); + + while (1) { + printf("tick\r\n"); + test_leds(); + } }