6 years, 1 month ago.

Problems with connection via serial port!

Good afternoon, I'm trying to control a small application on Android with MBED. What I want is that by pressing a button in my app send a character to MBED that receives it through the serial port and do one function or another depending on the character sent. I have the following code, but it does not do anything to me, I do not know if it is because something is missing:

PinName TX = PC_6;
PinName RX = PA_12;
Serial pc(TX, RX); //Puerto serie

int main(){
    pc.baud(9600);
    pc.attach(&recibeDatos);
}

void recibeDatos(){
    char byteRecibido = pc.getc(); //Devuelve el caracter
    switch(byteRecibido) {
        case 'A':
            avanza();
            break;
        case 'H':
            home();
            break;    
    }
}

Thank!!

1 Answer

6 years, 1 month ago.

Your program is exiting. Programs don't do anything after they have stopped running. :-)

Try:

int main(){
    pc.baud(9600);
    pc.attach(&recibeDatos);
    while (true) {
    }
}

Good again, still do nothing, I tried to put inside the main pc.attach (& get Data); , but nothing at all, would there be any solution? What I do is from an application by pressing a Home button sends a character 'H' where I supposedly read it from the function recibeDatos and depending on the character received will do one function or another, but I do not do anything, and I do not know It may be failing, how could it be?

Thanks again!!

posted by Jose Romero 12 Nov 2018