summaryrefslogtreecommitdiff
path: root/src/uart.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcsapce.com>2022-09-27 16:14:28 -0500
committerBrett Weiland <brett_weiland@bpcsapce.com>2022-09-27 16:14:28 -0500
commit94304b11e7220f060dbc345de5fa1952d0465016 (patch)
treef16e84c54b27f67e089ded1175fbf8b561896b42 /src/uart.c
parent7b006d6f2032ac46074d693ae59a971bee327ace (diff)
working on serial syncronization for programming eeprom
Diffstat (limited to 'src/uart.c')
-rw-r--r--src/uart.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/uart.c b/src/uart.c
index 3ba75db..ca1e587 100644
--- a/src/uart.c
+++ b/src/uart.c
@@ -1,6 +1,7 @@
#include <avr/io.h>
#include <stdio.h>
#include <util/setbaud.h>
+#include "pins.h"
/** UART notes
* UCSR0A:
@@ -35,27 +36,36 @@
* ____________________________________________________________
* UBRR0(H,L): baudrates
*
+ *
**/
//TODO replace with static void and just use high level functions?
void uart_sendbyte(uint8_t byte) {
- if(byte == '\n') uart_sendbyte('\r');
- loop_until_bit_is_set(UCSR0A, UDRE0);
+ UART_PORT &= ~(_BV(UART_RTS)); //us: ready to send
+ loop_until_bit_is_clear(UART_PORT, UART_CTS); //them: go ahead
+ //also wait for buffer to be empty, should never be a problem
+ loop_until_bit_is_set(UCSR0A, UDRE0); //done recieving
UDR0 = byte;
+ UART_PORT |= _BV(UART_RTS); //keep in mind cts is inverted; low is 1 and high is 0
}
//TODO replace with static void and just use high level functions?
uint8_t uart_recvbyte() {
- loop_until_bit_is_set(UCSR0A, RXC0);
+ loop_until_bit_is_clear(UART_PORT, UART_CTS); //wait for their request
+ UART_PORT &= ~(_BV(UART_RTS)); //hey, you can send now
+ loop_until_bit_is_set(UCSR0A, RXC0); //wait for them to actually send
+ UART_PORT |= _BV(UART_RTS); //okay, you can no longer send
return UDR0;
}
void uart_init() {
//set baud rate
+ UART_DDR |= _BV(UART_RTS);
+ UART_PORT |= _BV(UART_RTS); //keep in mind cts is inverted; low is 1 and high is 0
+
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
-
/**
TODO figure out why USE_2X is enable when it shoudn't be
//set baud rate