Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Baby-O serial not waiting (solved)


#1

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


#2

Hello.

It is difficult for me to help you troubleshoot the issue from your code snippet. Can you post your entire code here?

The wait_for_sending_to_finish() implementation in our example code actually just waits until the software transmission buffer in our serial library is empty. It does not wait for the UART hardware to finish sending the bytes that it has buffered.

- Amanda


#3

That is spot on, in order to prevent the Tx hardware to be disconnected too soon I need that 1ms waiting time, can even be us.

Thanks my system is working now.