11 years, 3 months ago.

Enabling serial RX interrupt breaks EthernetInterface.connect()

Hello,

In my code I want to use the ethernet functions and the serial RX interrupt.

Somehow if I enable the RX interrupt the ethernet and the serial RX interrupt seem to break both.

My code is as follows:

#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"

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

char serialBuffer[256];
unsigned char serialBufferLoc = 0;

//I know, not the best buffer but it works.
void rxInterrupt(void){
    serialBuffer[serialBufferLoc] = probe.getc();
    pc.putc(serialBuffer[serialBufferLoc]);

    if (serialBuffer[serialBufferLoc] == 0x0A) {
        //<Do somehing>;
    }
    serialBufferLoc++;
}

int main(void){
    //init the sensor serial port
    probe.baud(9600);
    probe.format(8,Serial::None,1);
    //attach the interrupt. this breaks the interrupts (combined with ethernet)
    probe.attach(&rxInterrupt,Serial::RxIrq);
    pc.baud(115200); //higher baudrate so I can transmit more data
    pc.format(8,Serial::None,1);
    pc.printf("Comtest, MBED started\r\n");
    char str[512];
    eth.init(); //Use DHCP
    eth.connect();
    //PUT data
    strcpy(str, "99");
    HTTPText outText(str);
    HTTPText inText(str, 512);
    printf("\r\nTrying to put resource...\r\n");
    int ret = http.put("http://httpbin.org/put", outText, &inText);
    if (!ret)
    {
      printf("Executed PUT successfully - read %d characters\r\n", strlen(str));
      printf("Result: %s\r\n", str);
    }
    else
    {
      printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
    }

    while(1){}
}

Is there someone who knows how I can use both? (An sample on how to use the RTOS for this is also ok)

2 Answers

11 years, 3 months ago.

Tim, With the new EthernetInterface, mbed RTOS is needed. The way serial interrupts has changed as a result. See the link towards the bottom of:

http://mbed.org/forum/mbed/topic/3414/

BTW: I'm still looking for a working set of EthernetInterface, USB UART, slow UART, local and SD Flash file systems all working together. It's been frustrating.

...kevin

Accepted Answer

Just curious, but in the ethernetinterface examples no RTOS is used. And only for the vodafone ethernet library it specifically says you need RTOS, is that really the case with also the default EthernetInterface? Going to use it myself soonish, and I dislike rtos.

posted by Erik - 27 Dec 2012
Tim Bots
poster
11 years, 3 months ago.

So after a lot of reading I still can't figure out what I'm doing wrong.

I now modified my interrupt code to

void rxInterrupt(void){
    uint32_t IRR3 = LPC_UART3->IIR;
    serialBuffer[serialBufferLoc] = LPC_UART3->RBR;

    if (serialBuffer[serialBufferLoc] == 0x0A) {
        //<do something>;
    }
    serialBufferLoc++;
}

This is based on the code from

Import programthreadinterrupt

Simple program that demonstrates how one might send signals to arbitrary threads from an ISR.

and

Import programSerial_interrupts_buffered

Serial Interrupt Library with mbed RTOS for multi-threading

(also see the notebook http://mbed.org/users/tylerjw/notebook/buffered-serial-with-rtos/)

If I remove all the ethernet library's (RTOS, ethernet, httpclient) the code runs fine but as soon as I import the library's (I don't even need to include them) the controller seems to "lock" on the 1st serial interrupt. (Also see http://mbed.org/forum/mbed/topic/3414/)

Any clues on how to debug/fix this?