Serial.flush on arduino mini??

Hi there, i'm working on controlling a robot with two xbees. My codes work perfectly with my mega5660, but i am using embedded arduino minis, with exactly the same code.

What happends is that, when i send a command, the command is executed but never stops. In my code i'm using serial.flush to avoid this, and it works perfectly on other arduino, but i just don't understand why it doesn't on the mini.

this is an example of my code: Serial.begin(115200) // for the xbee

void main { Serial.flush (); // just it case..

while (serial.available() > 0){ inChar = (); Serial.flush(); //

if ( inChar == 'A' ){ Serial.println("A"); //Do something Serial.flush(); } // close A }

action "A" is executed for ever, even though it works on my other arduino. Do you guys have any ideas?

What version of the IDE are you using ? There was a significant change to the operation of Serial.flush() from version 1.0 on. It no longer removes incoming data from the buffer.

thanks for your help! wow i didn't know that, i'm using 1.0.3 How can we manage to stop the incoming stream if serial.flush only waits for the buffer to be empty? it means we have to send realy sharp command, doesn't it??

while (Serial.available());

... does empty your incoming buffer.

But your description sounds like you're having another problem. Is it possible that you have a loopback at the serial interface? Does it work if you don't print out the same character as you're receiving?

well.. when i was prototyping i used my atmega5660 and it worked perfectly well. To debug i used to print out "A" when A was received, and i managed to get one single "A" sent and one single "A" received ( accurate receiption ).

I think i will try using this new function "Serial.event" and change my serial protocol. I will post here if any trouble still exist.. :roll_eyes:

this is an example of my code:

Bullpoop!. Your code looks NOTHING like that. Post some real code.

What is sending the serial data?

How will dumping random amounts of unread data solve your problem?