while (Serial.available() < 0) {
incomingByte = Serial1.read();
Two things here.
First, Serial.available only returns zero or positive values.
Second, why check one port to see if it has data available, and then read the data from another?
That suggest to me that you haven't fixed your code, and that you're reading -1 == "No serial data available" from your port.
Please post your code.
Hi AWOL,
I fixed the code already.
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initial condition
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const int RTS = 4; //1= transmit, 0 =receive
byte ping =0x01;
byte READ =0x02;
byte WRITE =0x03;
byte REG =0x04;
byte ACTION=0x05;
byte RESET =0x06;
byte SYNC =0x83;
byte BEGIN =0xff;
int incomingByte = 0;
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Setup Function
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup () {
pinMode(RTS, OUTPUT);
Serial.begin(57600);
Serial1.begin(57600);
}
// Main function
void loop()
{
byte notchecksum;
byte motor_ID=0x01;
byte length=0x02;
digitalWrite(RTS,HIGH);
delay (5);
notchecksum=~(motor_ID + length + ping);
Serial1.write(BEGIN);
Serial1.write(BEGIN);
Serial1.write(motor_ID);
Serial1.write(length);
Serial1.write(ping);
Serial1.write(notchecksum);
digitalWrite(RTS,LOW);
// send data only when you receive data:
while (Serial1.available() == 0)
{
incomingByte = Serial1.read();
}
incomingByte = Serial1.read();
Serial.print(Serial1.available(),HEX);
delay(1000);
}//This is program to send data to servo
Now, is the serial monitor does not give any display. I suspect that it keep stuck inside the WHILE loop.
Now, I am wondering if my Dynamixel motor does not send any data or, My 485 breakout circuit does not send me any data.
Do you have any idea?
Yup.
Just in case that I miss the data transmitted.
However, I do not get any result out. As I expected when the serial1 received the data, it should go out of the loop and print the value that is stored at "inbyte"
I'd say you're pretty much guaranteeing that you will miss data, in very nasty, creative ways.
Think.
Test if there's a character available.
An interrupt happens to occur before the "read", and character is put in the receive buffer.
Interrupt returns, and you read the character, 'cos that's what your loop does.
Test to see if there's a character available.
Oops.