Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created October 4, 2013 18:27
Show Gist options
  • Save dagon666/6830405 to your computer and use it in GitHub Desktop.
Save dagon666/6830405 to your computer and use it in GitHub Desktop.
usart poll rx/tx
unsigned char serial_poll_recv(unsigned char *a_data, unsigned int a_size) {
unsigned int cnt = a_size;
while (a_size) {
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
*a_data = UDR0;
a_data++;
a_size--;
}
return cnt;
}
unsigned int serial_poll_send(void *data, unsigned int a_size) {
unsigned int i = 0x00;
while (i < a_size) {
// wait until usart buffer is empty
while ( bit_is_clear(UCSR0A, UDRE0) );
// send the data
UDR0 = ((unsigned char *)data)[i++];
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment