Serial write time
hi,
i trying reduce time taken serial.write(...) function. theoretically, time taken function should 9 / baudrate send 1 byte. used following code verify :
this code sends byte every 1 sec , prints time taken between line , c. problem when comment line b, time taken instruction "serial2.write(byte(5));" 20µs, every baudrate... when uncomment line b, time taken approximately 20 + 9/baudrate µs every beaudrate.
in opinion, because first line copying byte write buffer, , second waiting sent.
1) assumption right ?
2) why take long copy byte (20µs !) ? want make quicker because constant time problem send data @ high speed (i send data possible , using baudrate of 460800 loose half of time copying in buffer)
any appreciated :~
i trying reduce time taken serial.write(...) function. theoretically, time taken function should 9 / baudrate send 1 byte. used following code verify :
code: [select]
void setup(){
serial.begin(115200);
serial2.begin(300);
}
unsigned long t;
int i=0;
void loop(){
if(i==0){
t=micros(); // line a
serial2.write(byte(5));
serial2.flush(); // line b
t=micros()-t; // line c
delay(50);
serial.println(t);
i++;
}
else{
if(i==1){
t=micros();
i++;
}
else{
if(micros()-t > 1000000){
i=0;
}
}
}
}
this code sends byte every 1 sec , prints time taken between line , c. problem when comment line b, time taken instruction "serial2.write(byte(5));" 20µs, every baudrate... when uncomment line b, time taken approximately 20 + 9/baudrate µs every beaudrate.
in opinion, because first line copying byte write buffer, , second waiting sent.
1) assumption right ?
2) why take long copy byte (20µs !) ? want make quicker because constant time problem send data @ high speed (i send data possible , using baudrate of 460800 loose half of time copying in buffer)
any appreciated :~
quote
theoretically, time taken function should 9 / baudrate send 1 byte.
start + stop + 8 data = 10.
Arduino Forum > Using Arduino > Programming Questions > Serial write time
arduino
Comments
Post a Comment