11 years, 2 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

11 years, 2 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.

Accepted Answer

thank you, can you help with a eg. how to do that please... thank you

posted by Danilo Teran 01 Mar 2013

i change the program... but i have the same error i can't go out from the interrupt..

posted by Danilo Teran 01 Mar 2013

You have to call a device.getc()

posted by Wim Huiskamp 01 Mar 2013