Hi, I have used the serial ports separately, but now my application requieres 2 serial ports, but i fail.
i have tested separatedly and works!, the first device is an IMU at 57600 baudrate, the other is a xbee working at 115200, i work with interrupts and the scanf. but i dont know if is not possible to use 2 interruptions? could someone tell me what could be happening? because its rare, the IMU is always connected to mbed, and scanf works good, then the xbee starts the transmission and the scanf of IMU sucks :( and the scanf of xbee works properly, if i cancell the attach of IMU the xbee also works good, but at same time fail.
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
DigitalOut dg(p21);
DigitalOut dh(p22);
Serial imu(p9,p10);// tx,rx
Serial xbee(p13,p14);
float Y=0,P=0,R=0;
int pd=0,rd=0,yd=0,act=0;
void rximu() {
led3 = !led3;
dg=1;
imu.scanf("#YPR=%f,%f,%f\r\n",&Y,&P,&R);
if(R>0){
led1=1;
}else{
led1=0;
}
dg=0;
}
void rxbee() {
led2 = !led2;
dh=1;
xbee.scanf("X:%d,%d,%d,%d\r",&pd,&rd,&yd,&act);
if(act==1){
led4=1;
}else{
led4=0;
}
dh=0;
}
int main() {
imu.baud(57600);
xbee.baud(115200);
imu.attach(&rximu);
xbee.attach(&rxbee);
while(1) {
}
}
Thanks
I'am new to mbed and C.
Since many hours i try to implement MODSERIAL into a library. Using MODSERIAL inside main.cpp is quite easy and works very well. But when I try to convert the code into a library it does not work. Even when I reduce the code to a minimum it compiles but it does not run (mled1 does not blink).
main.cpp
#include "SBUS.h" #include "MODSERIAL.h" #include "mbed.h" DigitalOut mled1(LED1); SBUS sbus2(p28, p27); //when commented out, main() works int main() { while (1) { wait(0.2); mled1=!mled1; } }SBUS.h
#ifndef MBED_SBUS_H #define MBED_SBUS_H #include "MODSERIAL.h" #include "mbed.h" class SBUS { public: SBUS(PinName tx, PinName rx); MODSERIAL sbus_; }; #endifSBUS.cpp
#include "SBUS.h" #include "MODSERIAL.h" #include "mbed.h" DigitalOut mled2(LED2); SBUS::SBUS(PinName tx, PinName rx) : sbus_(tx, rx) { mled2=1; }Do I miss something? How to use the .attach functionality?
thanks