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.
12 years, 8 months ago.
SERIAL
HI, I'M NEW WITH THIS.. i'm using this code to make serial interrupts, but when i go on the interrupt recepcion on the micro, i can't get out of here, i think it's happen 'cause register of interrupt is with a data, HOW I CAN ERASE DATAS TO GET OUT OF THE INTERRUPTS
MY BIGGEST PROBLEM IS WITH THE RECEPTION INTERRUPTS.
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
Serial device(p9,p10);
// Circular buffers for serial TX and RX data - used by interrupt routines
const int buffer_size = 255;
// might need to increase buffer size for high baud rates
char tx_buffer[buffer_size];
char rx_buffer[buffer_size];
volatile int tx_in=0;
volatile int tx_out=0;
volatile int rx_in=0;
volatile int rx_out=0;
/*NVIC_EnableIRQ(UART1_IRQn);*/
void Tx_interrupt();
void Rx_interrupt();
int main() {
device.baud(9600);
// Setup a serial interrupt function to receive data
device.attach(&Rx_interrupt, Serial::RxIrq);
// Setup a serial interrupt function to transmit data
device.attach(&Tx_interrupt, Serial::TxIrq);
NVIC_EnableIRQ(UART1_IRQn);
while(1) {
led3=1;
wait(0.3);
led3=0;
wait(0.3);
}
}
void Rx_interrupt() {
led1=1;
led3=0;
wait(0.2);
led1=0;
wait(0.2);
}
void Tx_interrupt() {
led2=1;
wait(0.3);
led2=0;
return;
}
1 Answer
12 years, 8 months ago.
You need to actually read the data from the serial port to clear the interrupt in the rx_int function.
Please use <<code>> and <</code>> tags to make posted code more readable.