11 years, 3 months ago.

uart.attach(&uart_interrupt(), Serial::RxIrq); (Error 158)

First off let me explain that I am a complete neophyte here.

And also thanks to Christian and Rainer for getting me this far.

First off let me explain that I am a complete neophyte here.

My day job is as a consultant for projects ranging from Architectural Engineering to product development, management, etc.

The purpose of the code is to eventually trigger relays, which I am using LED2-4 in place of.

In operation function1 will clear all relays (logic1 or float) function2 - functionx will turn on the relay (logic 0)

Each function is an 8byte word that always start 0xF9, 0xFF; and end 0x00 Communication is via RS-232 or 485 (RS-232 seems to work fine)

Also LED1 will flash if Uart active. (I probably don't need this if the MBED LED does the same thing.

I am hung up on an error at ... uart.attach(&uart_interrupt(), Serial::RxIrq);

Error 158 ("Expression must be an Ivalue or function designator")

I am also unsure of the placement for "int i = 0"

The purpose of the code is to eventually trigger relays, which I am using LED2-4 in place of.

In operation function1 will clear all relays (logic1 or float) function2 - functionx will turn on the relay (logic 0)

Each function is an 8byte word that always start 0xF9, 0xFF; and end 0x00 Communication is via RS-232 or 485 (RS-232 seems to work fine)

Also LED1 will flash if Uart active. (I probably don't need this if the MBED LED does the same thing.

  1. include "mbed.h"

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};

int i = 0;

Serial pc(USBTX, USBRX);

Serial uart(p9, p10); Connect TX to RX (p9 to p10)

void uart_interrupt()

{

if(uart.readable()) { check availability

buffer[i] = uart.getc(); copy the serial input to buffer

i++; increment buffer value

}

}

DigitalOut uart_activity(LED1);

DigitalOut led2(LED2);

DigitalOut led3(LED3);

DigitalOut led4(LED4);

assign led function

int main()

{

uart.baud(2400);

uart.attach(&uart_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 == function1)

led4 = 1; led 1 on if function1

while(1) {

if(pc.readable()) {

uart.putc(pc.getc());

pc_activity = !pc_activity

}

uart_activity = 0; turn off rx led

if(uart.readable()) {

pc.putc(uart.getc());

uart_activity = !uart_activity;

wait(0.01); Turn on LED 1 when data received

void Tx_interrupt();

void Rx_interrupt();

void send_line();

void read_line();

}

}

}

}

I tried this code (After some deletion of non-comments and pc_activity:

#include "mbed.h"

DigitalOut uart_activity(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

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

char buffer[8];
char function1[] = {0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xA1, 0xC2, 0x00};
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};

int i = 0;

void uart_interrupt()
{
    if(uart.readable()) {
        buffer[i] = uart.getc();
        i++;
    }
}

int main()
{
    uart.baud(2400);
    uart.attach(&uart_interrupt, Serial::RxIrq);
    while(true) {
        if(!memcmp(buffer, function1, 8)) {
            led4 = 1;
            i = 0;
        }
        if(buffer == function1) {
            led4 = 1;
        }
        while(1) {
            if(pc.readable()) {
                uart.putc(pc.getc());
                //pc_activity = !pc_activity;
            }
            uart_activity = 0;
            if(uart.readable()) {
                pc.putc(uart.getc());
                uart_activity = !uart_activity;
                wait(0.01);
                void Tx_interrupt();
                void Rx_interrupt();
                void send_line();
                void read_line();
            }
        }
    }
}
posted by Christian Lerche 27 Dec 2012

2 Answers

11 years, 3 months ago.

This one compiles perfect with LPC1768:

You'll notice the pc_activity is commented out.

#include "mbed.h"

DigitalOut uart_activity(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

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

char buffer[8];
char function1[] = {0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xA1, 0xC2, 0x00};
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};

int i = 0;

void uart_interrupt()
{
    if(uart.readable()) {
        buffer[i] = uart.getc();
        i++;
    }
}

int main()
{
    uart.baud(2400);
    uart.attach(&uart_interrupt, Serial::RxIrq);
    while(true) {
        if(!memcmp(buffer, function1, 8)) {
            led4 = 1;
            i = 0;
        }
        if(buffer == function1) {
            led4 = 1;
        }
        while(1) {
            if(pc.readable()) {
                uart.putc(pc.getc());
                //pc_activity = !pc_activity;
            }
            uart_activity = 0;
            if(uart.readable()) {
                pc.putc(uart.getc());
                uart_activity = !uart_activity;
                wait(0.01);
                void Tx_interrupt();
                void Rx_interrupt();
                void send_line();
                void read_line();
            }
        }
    }
}

11 years, 3 months ago.

You want to put <<code>> and <</code>> around it (each on its own line), then it is formatted as code and alot better readable (also you dont have to enter blank lines everywhere as I expect you did).

Regarding your attach, just remove the '()'. They are only used if you want to execute it, you just want to give a pointer to the function. Your int i, I think it is the correct place, but it is a good idea to add 'volatile' in front of it. That tells the compiler it isnt allowed to optimize the variable. Since generally compilers are too stupid to understand interrupt routines, it otherwise might think i never changes and because of that remove half your code in optimizations.