Uart Last Transmitted Byte Flag

Is there a way to know when the last byte of a buffer is shifted out the uart register?

I’m sending a message to a gps receiver that changes it’s baudrate. Once the message is received the gps receiver changes it’s baudrate and then sends and acknowledge message. I need to be able to change the baudrate of my system after sending the message out but before receiving the acknowledge messaged from the receiver.

I’ve tried using:

gpsUart.Write(Globals.gpsTransmitBuffer, 0, gpsTransmitLength)
while(gpsUart.BytesToWrite != 0)

This didn’t work as the BytesToWrite were immediately 0.

A work around is to delay for the amount of time it takes to transmit the number of bytes at the given baudrate…the following code works:

gpsUart.Write(Globals.gpsTransmitBuffer, 0, gpsTransmitLength)

Thread.Sleep(30);

gpsUart.SetActiveSettings(new UartSetting() { BaudRate = 115200 });

while (UbloxDecoder.UbloxResponseMessage(gpsUart, NMEA, (byte)UbloxMessageClass.CFG, (byte)UbloxMessageID.PRT_CFG) != 1)	
	{ Thread.Sleep(50);	}

I feel like the delay method opens myself up to potential issues.

Any feedback is appreciated…Thank you

You could technically read the micro registers directly but I would go with the delay approach.

while(gpsUart.BytesToWrite != 0)

Yes, this only indicates that no more bytes remain in the FIFO at the driver level, but it does not guarantee that all bytes have been transmitted at the lower level.

try gpsUart.Flush();

Thank you for the replies.

For the meantime, I ended up using the delay approach.