11 years, 11 months ago.

error 158 serial.attach(&serial_interrupt(), Serial::RxIrq);<</code>>

The program is hanging at the line that reads : serial.attach(&serial_interrupt(), Serial::RxIrq); :with an error 158 issued on the compile

I think the serial interrupt is not setting and needs to be a logic zero when there is no interrupt . Final code will be for UART pin 9&10 with baud 2400 I need the LEDs to light when function2 to 4 are activated, and turn off with function1

#include "mbed.h"

DigitalOut led1(LED1);  //assign led function
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);


char buffer[8];
char function1[] = {0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xA1, 0xC2, 0x00}; // Array for function
char function2[] = {0xF9, 0xFF, 0xBF, 0xFF, 0xFF, 0xA1, 0x42, 0x00};
char function3[] = {0xF9, 0xFF, 0x7F, 0xFF, 0xFF, 0xA1, 0xC2, 0x00};
char function4[] = {0xF9, 0xFF, 0xE8, 0x99, 0xDF, 0xA1, 0x66, 0x00};

Serial serial(p9, p10);
Serial pc(USBTX, USBRX);

int i = 0;

void serial_interrupt()
{

    unsigned char d;
    if(serial.readable()) {         // check availability
        d = serial.getc();
        if (d == 0xf9) {
            buffer[0] = d;
            i = 1;
            led1 = 1;
        } else {
            buffer[i] = d;   // copy the serial input to buffer
            i++;              // increment buffer value
        }
    }
}
int main()
{

    serial.attach(&serial_interrupt(), Serial::RxIrq);
    while(true) {
        if(!memcmp(buffer, function1, 8)) {
            led4 = 1 ;
            i = 0;                       // doing this prevents buffer overflow, i.e. you reset i, to point to buffer[0] again.

            if(buffer == function2);
            led3 = 1;


        }                                    // And so on, you get the idea.

    }
}
Be the first to answer this question.