L432kc uart with xbee

hello,i use a l432kc component and i need to communicate with a xbee s2c through UART and i don’t know what is wrong with my program ,some one can help me?
I correctly have connected the pins to the l432kc (Pin1xbee(3v3),Pin2xbee(txl432kc),Pin3xbee(rxl432kc),Pin10xbee(gnd)
here’s my program
/* mbed Microcontroller Library

  • Copyright (c) 2019 ARM Limited
  • SPDX-License-Identifier: Apache-2.0
    */

#include “mbed.h”
#include “platform/mbed_thread.h”

// Blinking rate in milliseconds
#define BLINKING_RATE_MS 1000
RawSerial pc(USBTX,USBRX);
RawSerial xbee(PA_9,PA_10);
char car_recu;
bool ok;

void callback_ex()
{
// Note: you need to actually read from the serial to clear the RX interrupt
car_recu=(xbee.getc());
ok=true;
// led = !led;
}

int main()
{

pc.baud(9600);
xbee.baud(9600);


while (true) {

    thread_sleep_for(BLINKING_RATE_MS);
    xbee.printf("+++");
    while (true) {
        if (ok==true) {
            pc.putc(car_recu);
            ok=false;
        }
    }
     pc.printf("+++");







    thread_sleep_for(5000);
}

}

Hi there,

please be so kind and fill these three symbols ``` before and after your code for correct formating. You can edit your post via pen icon.

I do not know what you exactly want from your code but

    while (true) {
        if (ok==true) {
            pc.putc(car_recu);
            ok=false;
        }
    } 
   // everything below will not be executed because of endless loop above
     pc.printf("+++");
     thread_sleep_for(5000);

Without interrupts and for both direction it can be something like that maybe

while(true){
   if(xbee.readable()){
      pc.putc(xbee.getc());
   }
   if(pc.readable()){
      xbee.putc(pc.getc());
   }
}

BR, Jan

1 Like