Hi everyone!
I'm almost wrapped up on getting this Soft UART down to a science, So I'll sound by laying down my foundation and see if I'm on the right track. I am currently hooked up to a GPS module and am receiving a 4800 BUAD communication from the unit. Right now I am sleeping in Microsecond's to help bitbang the incoming stream. However what is the best way to do this?
1: 1Second / 4800Buad / = 0.00020833333
or
2: A different forumla is required?
Should I always have the UC sleep in US or should I sleep by Ticks?
Inbetween bytes coming through the communication I need to check to see if the Char I received was a '$' and a LF on the end to mark the end of the communication. However It appears it effects the timing of the incoming message. What is the best way to resolve this issue by the book? Calculate how much time in UC the checks take and subtract it from the sleep in UC (Some what calibrate it to the code) or is there another alternative? If I do calculate the difference it appears my sending and recv timing will have to be a different value because this check won't exist when sending data?
Thank you for your input!
-Agent
I'm almost wrapped up on getting this Soft UART down to a science, So I'll sound by laying down my foundation and see if I'm on the right track. I am currently hooked up to a GPS module and am receiving a 4800 BUAD communication from the unit. Right now I am sleeping in Microsecond's to help bitbang the incoming stream. However what is the best way to do this?
1: 1Second / 4800Buad / = 0.00020833333
or
2: A different forumla is required?
Should I always have the UC sleep in US or should I sleep by Ticks?
Inbetween bytes coming through the communication I need to check to see if the Char I received was a '$' and a LF on the end to mark the end of the communication. However It appears it effects the timing of the incoming message. What is the best way to resolve this issue by the book? Calculate how much time in UC the checks take and subtract it from the sleep in UC (Some what calibrate it to the code) or is there another alternative? If I do calculate the difference it appears my sending and recv timing will have to be a different value because this check won't exist when sending data?
Thank you for your input!
-Agent
Code:
while(true)
{
while(PINA & (1<<UART_GPSRX_INTERRUPT))
{
}
_delay_us(SleepRX4800 * 1.5);
for(uint8_t i = 0; i < 8; i += 1)
{
if(PINA & (1<<UART_GPSRX_INTERRUPT)) //RX PIN IS HIGH
{
uart_GPS_rx_buffer[uart_GPS_rx_buff_end] |= (1 << i); //RX PIN IS HIGH, try not to change any code here its timing sensitive
}
else
{
uart_GPS_rx_buffer[uart_GPS_rx_buff_end] &= ~(1 << i); //RX PIN IS LO
}
if(i != (UART_RX_BUFFER_SIZE - 1))
{
_delay_us(SleepRX4800);
}
}
if(uart_GPS_rx_buffer[0] == '$' && uart_GPS_rx_buffer[uart_GPS_rx_buff_end] == 0x0A)
{
break;
}
if(uart_GPS_rx_buffer[0] == '$')
{
uart_GPS_rx_buff_end++;
}
}