I am working on a Grbl pendant with a Baby-O and a joystick. For communicating with the Grbl controller I need to switch the Tx line ON, send my message and disconnect the Tx line so UGS can send the machine code to the router.
For this I use the following code:
if (((PIND&(1<<DDD7))==0)&&(jog==0)) // Check button
{
Tx_ON; // Tx line connected through 4066N Switch
memcpy_P(send_buffer, PSTR("$J=G91G21 Z1.000F300"), 20);
serial_send(send_buffer, 20);
wait_for_sending_to_finish();
uar_putchar(0x0A);
wait_for_sending_to_finish();
jog = jog+1;
delay_ms(1); // If wait for sending did its job this would not be necessary
Tx_OFF; // Tx line disconnected
}
If I look into the Tx output before the switch it shows all the text
If I look into the Tx output after the switch it falls short by 2 characters and without the 0x0A
When I add 1ms delay then it work like a dream
I get the impression that wait_for_sending_to_finish is not waiting
Atmel Studio 7 with Pololu Library