8 years, 5 months ago.

write and read is inaccessible.

I want to have PC to MBED async communication over USB port. I following pretty much code from this repo

Repository: Serial-LowPower-Demo

. Here is the code I have

#include "mbed.h"

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
Serial pc(USBTX, USBRX);
uint8_t rxBuffer[5];
bool on = false;

event_callback_t eSerialCb;
void serialCb(int event){
    unsigned char i;
    
    if (event & SERIAL_EVENT_RX_CHARACTER_MATCH){
        myled2 = on ? 0 : 1;
        on = !on;
        for (i = 0; i < 5; i++){
            if (rxBuffer[i] == '$') { break; }
        }
    } else if (event & SERIAL_EVENT_RX_COMPLETE) {
        i = 5 - 1;
    } else {
        rxBuffer[0] = 'E';
        rxBuffer[1] = 'R';
        rxBuffer[2] = 'R';
        rxBuffer[3] = '!';
        i = 3;
    }
    
    pc.write(rxBuffer, i+1, 0, 0);
    
    pc.read(rxBuffer, 5, eSerialCb, SERIAL_EVENT_RX_ALL, '$');
}

int main() {
    eSerialCb.attach(serialCb);
    
    pc.baud(115200);
    pc.printf("Send '$'.\r\n");
    pc.read(rxBuffer, 5, eSerialCb, SERIAL_EVENT_RX_ALL, '$');
    
    while(1) {
        myled1 = 1;
        wait(0.2);
        myled1 = 0;
        wait(0.2);
    }
}

However get following errors

- Error: Function "mbed::Stream::read" (declared at <a href="#" onmousedown="mbed_doc_goto('/mbed_blinky_async//extras/mbed_9296ab0bfc11/Stream.h', '46'); return false;">/extras/mbed_9296ab0bfc11/Stream.h:46</a>) is inaccessible in "main.cpp", Line: 40, Col: 9

- Error: Function "mbed::Stream::write" (declared at <a href="#" onmousedown="mbed_doc_goto('/mbed_blinky_async//extras/mbed_9296ab0bfc11/Stream.h', '45'); return false;">/extras/mbed_9296ab0bfc11/Stream.h:45</a>) is inaccessible in "main.cpp", Line: 30, Col: 9

I also get other error saying too many arguments for read and write. Furthermore, the "live documentation" in the window only shows read, and write function for other port types i.e. DigitalOut, PwnOut, AnalogOut etc.

I don't understand why these are happening, and why it won't work. Is there a different way to have async communication between PC and MBED over USB port? The board I'm using is LPC1768.

1 Answer

8 years, 5 months ago.

LPC1768 is not compatible with the low power APIs (the ones with the async implementation) for Serial, SPI or I2C. Only the the EFM32 Gecko platforms from Silicon Labs are compatible with these APIs.

If you would have included the following compatibility-check from the above Silicon Labs test program in your code too, you would have got a meaningful compiler error message for incompatible platforms (like the LPC1768):

/*-------- Check if platform compatible ----------*/
#if DEVICE_SERIAL_ASYNCH
Serial pc(USBTX, USBRX);
#else
#error "Platform not compatible with Low Power APIs for Serial"
#endif

Regards
Neni

Accepted Answer

Thanks, is there any other way to have event callback design implementation, when receiving a char from PC? Or does it have to be synchronous? Also is this the same problem https://developer.mbed.org/questions/61479/I2C-has-no-member-transfer-error/ as above?

posted by Chandan Siyag 10 Nov 2015

Yes, it's basically the same thing for I2C. The transfer method is only implemented in the low power I2C API for the Silicon Labs platforms.

For Serial (UART) you can use the attach method, which is implemented for most or all platforms. In the attach method you can specify a callback function to be called in the case a char was received (RX-Interrupt) or in the case the TX-Buffer is not full (TX-Interrupt). See the API for the correct syntax.

posted by Nenad Milosevic 10 Nov 2015