Report
2 years, 9 months ago.

Delay on serial communication between mbed and arduino

Sorry for my bad english :(

Hi Guys, i have a project to make a communication between arduino mega and nucleo446 using mbed. i have done sending some char from mbed to arduino and its worked. but the problem is the data is not received in arduino in real time, there is a delay about 0.5sec... here is my code :

Mbed

#include "mbed.h"
 
Serial pc(USBTX, USBRX);    // tx, rx
Serial mega(PA_9, PA_10); //TX, RX
Timer timer;
 
int main() {
    pc.baud(9600);
    mega.baud(9600);
    pc.printf("Starting...\n\r");
 
    timer.start();
    while (1) {
        if (pc.readable()){
            char x=pc.getc();
        if (timer.read() > 1) {
            pc.printf("Start Writing!\n\r");
            mega.putc(x);
            timer.reset();
                      pc.printf("Done Writing!\n\r");
        }
            }       
    }
}

Arduino Mega

int x;
 
void setup()
{
 
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Starting...");
}
 
void loop() {
  if (Serial1.available()) {
    Serial.print("Got something!  ");
    x = Serial1.parseInt();
    Serial.println(x);
  }
 
}

Sorry for my bad english :(

Comment on this question
Be the first to answer this question.

You need to log in to post a question