Fixed serial.c after tests on real hardware
This commit is contained in:
parent
74db3e6c5b
commit
553c44a93f
4
main.c
4
main.c
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
sei();
|
||||||
|
|
||||||
serial_init(BAUD_RATE);
|
serial_init(BAUD_RATE);
|
||||||
protocol_init();
|
protocol_init();
|
||||||
settings_init();
|
settings_init();
|
||||||
@ -45,8 +47,6 @@ int main(void)
|
|||||||
gc_init();
|
gc_init();
|
||||||
limits_init();
|
limits_init();
|
||||||
|
|
||||||
sei();
|
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
sleep_mode(); // Wait for it ...
|
sleep_mode(); // Wait for it ...
|
||||||
protocol_process(); // ... process the serial protocol
|
protocol_process(); // ... process the serial protocol
|
||||||
|
11
serial.c
11
serial.c
@ -42,11 +42,15 @@ uint8_t tx_buffer[TX_BUFFER_SIZE];
|
|||||||
uint8_t tx_buffer_head = 0;
|
uint8_t tx_buffer_head = 0;
|
||||||
volatile uint8_t tx_buffer_tail = 0;
|
volatile uint8_t tx_buffer_tail = 0;
|
||||||
|
|
||||||
|
static void set_baud_rate(long baud) {
|
||||||
|
uint16_t UBRR0_value = ((F_CPU / 16 + baud / 2) / baud - 1);
|
||||||
|
UBRR0H = UBRR0_value >> 8;
|
||||||
|
UBRR0L = UBRR0_value;
|
||||||
|
}
|
||||||
|
|
||||||
void serial_init(long baud)
|
void serial_init(long baud)
|
||||||
{
|
{
|
||||||
UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
|
set_baud_rate(baud);
|
||||||
UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1);
|
|
||||||
|
|
||||||
/* baud doubler off - Only needed on Uno XXX */
|
/* baud doubler off - Only needed on Uno XXX */
|
||||||
UCSR0A &= ~(1 << U2X0);
|
UCSR0A &= ~(1 << U2X0);
|
||||||
@ -96,8 +100,7 @@ SIGNAL(USART_UDRE_vect) {
|
|||||||
|
|
||||||
uint8_t serial_read()
|
uint8_t serial_read()
|
||||||
{
|
{
|
||||||
if (rx_buffer_head != rx_buffer_tail) {
|
if (rx_buffer_head == rx_buffer_tail) {
|
||||||
// Return magic number if no data pending
|
|
||||||
return SERIAL_NO_DATA;
|
return SERIAL_NO_DATA;
|
||||||
} else {
|
} else {
|
||||||
uint8_t data = rx_buffer[rx_buffer_tail];
|
uint8_t data = rx_buffer[rx_buffer_tail];
|
||||||
|
Loading…
Reference in New Issue
Block a user