Created
October 4, 2013 18:27
-
-
Save dagon666/6830405 to your computer and use it in GitHub Desktop.
usart poll rx/tx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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