Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hello All,
I have a problem that is frustrating my progress:
In order to test the USART I wrote a program to write data to the serial port on the mbed. My goal was to test the USART using a loopback and an interrupt. The idea is to send one byte out of the USART and toggle an LED in the interrupt handler when the byte is received back. When I run the program both my test LEDs remain solid. Additionally, I did not connect the TX and RX pins together so there is no reason for the LED to assert. Could you please have a look below and let me know if there is something obvious that is being overlooked? Thanks in advance!!
#include "mbed.h" Serial Device(p9, p10); // P9 and P10 UART pins DigitalOut Led1(LED1); DigitalOut Led2(LED2); /************************** ** RX Interrupt Handler **************************/ void RxInterrupt() { if( Led2.read() ) { Led2.write(0); } else { Led2.write(1); } } /************************** ** Main **************************/ int main() { // Configure serial port Device.baud(9600); // Baud rate Device.attach( &RxInterrupt, Serial::RxIrq ); // RX interrupt handler // Initialize Led1.write(0); Led2.write(0); while(1) { Device.putc( 0x02 ); if( Led1.read() ) { Led1.write(0); } else { Led1.write(1); } wait( 2.0 ); // Sleep 2 second } }