Added prototypes to header and function defs for runtime functions to change parity and stop bits.
This commit is contained in:
parent
f4aef61b0e
commit
5b265a5258
67
avr_usart.c
67
avr_usart.c
|
@ -15,6 +15,7 @@
|
||||||
//Globals
|
//Globals
|
||||||
//#############################
|
//#############################
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
led_blink();
|
led_blink();
|
||||||
|
@ -53,7 +54,8 @@ int main() {
|
||||||
/*
|
/*
|
||||||
* Input: None
|
* Input: None
|
||||||
* Output: None
|
* Output: None
|
||||||
* Description: init usart0 hardware in async mode
|
* Description: init usart0 hardware in async mode,
|
||||||
|
* This sets up the connection with default params 8-n-1
|
||||||
*/
|
*/
|
||||||
void init_usart0(void) {
|
void init_usart0(void) {
|
||||||
//setup stuff for usart communications.
|
//setup stuff for usart communications.
|
||||||
|
@ -70,10 +72,7 @@ void init_usart0(void) {
|
||||||
#else
|
#else
|
||||||
UCSR0A &= ~(1<<U2X0);
|
UCSR0A &= ~(1<<U2X0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//setting the data frame format
|
//setting the data frame format
|
||||||
UCSR0C = (0<<UMSEL01)|(0<<UMSEL00)| //Async
|
UCSR0C = (0<<UMSEL01)|(0<<UMSEL00)| //Async
|
||||||
(0<<UPM01)|(0<<UPM00)| //Parity bits
|
(0<<UPM01)|(0<<UPM00)| //Parity bits
|
||||||
|
@ -155,6 +154,66 @@ void serial0_write(unsigned char* buffer, uint8_t write_length) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input: none
|
||||||
|
* Output: none
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
void serial0_enable_line_feeds(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input: none
|
||||||
|
* Output: none
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
void serial0_enable_carriage_returns(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input: A parity setting as a 8bit uint
|
||||||
|
* Output: none
|
||||||
|
* Description: 0val clears for no parity
|
||||||
|
* 1val sets positive parity
|
||||||
|
* 2val sets negative parity
|
||||||
|
*/
|
||||||
|
void serial0_enable_parity_bit(uint8_t pos) {
|
||||||
|
switch(pos) {
|
||||||
|
case 0:
|
||||||
|
UCSR0C &= ~((1<<UPM01)|(1<<UPM00)); //Clear all.
|
||||||
|
case 1:
|
||||||
|
UCSR0C &= ~(1<<UPM00); //Make sure that the negative parity if off.
|
||||||
|
UCSR0C |= (1<<UPM01); //Set the positive parity
|
||||||
|
case 2:
|
||||||
|
UCSR0C |= (1<<UPM01)|(1<<UPM00); //Set both bits for neg parity
|
||||||
|
default:
|
||||||
|
;//Do nothing, just put here because
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input: number of stop bits
|
||||||
|
* Output: none
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
void serial0_set_stop_bits(uint8_t number) {
|
||||||
|
//clear all the set bits to start off.
|
||||||
|
UCSR0C &= ~(1<<USBS0);
|
||||||
|
switch(number) {
|
||||||
|
case 0:
|
||||||
|
;
|
||||||
|
case 1:
|
||||||
|
;
|
||||||
|
case 2:
|
||||||
|
UCSR0C |= (1<<USBS0);
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inupt: A serialbuffer and length
|
* Inupt: A serialbuffer and length
|
||||||
* Output: None
|
* Output: None
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
//#############################
|
//#############################
|
||||||
|
|
||||||
#define USE_U2X 0
|
#define USE_U2X 0
|
||||||
|
#define CARRIAGE_RETURN 1
|
||||||
|
#define LINE_FEED 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#############################
|
//#############################
|
||||||
|
@ -56,8 +59,10 @@ void serial0_read_with_err_checking(unsigned char* buffer, uint8_t buf_length);
|
||||||
void serial0_set_baud(uint8_t baud);
|
void serial0_set_baud(uint8_t baud);
|
||||||
void seiral0_enable_timeouts(uint8_t ms);
|
void seiral0_enable_timeouts(uint8_t ms);
|
||||||
void serial0_flush_rxbuf(void);
|
void serial0_flush_rxbuf(void);
|
||||||
|
void serial0_enable_line_feeds(void);
|
||||||
|
void serial0_enable_carriage_returns(void);
|
||||||
|
void serial0_enable_parity_bit(uint8_t pos);
|
||||||
|
void serial0_set_stop_bits(uint8_t number);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue