From 89a9b79aa99ddbfc729c6990ad35b0ffd334de04 Mon Sep 17 00:00:00 2001 From: maddiebaka Date: Sun, 26 Apr 2026 11:00:40 -0400 Subject: [PATCH] usart character output --- platformio.ini | 2 +- src/main.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index f90deed..000a448 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,7 @@ [env:pro16MHzatmega328] platform = atmelavr board = pro16MHzatmega328 -monitor_speed = 115200 +monitor_speed = 9600 lib_deps = https://github.com/Sylaina/bme280.git diff --git a/src/main.c b/src/main.c index fcb82ce..a3ed180 100644 --- a/src/main.c +++ b/src/main.c @@ -3,12 +3,38 @@ * See LICENSE for details. */ +#define F_CPU 16000000UL +#define BAUD 9600 + #include #include +#include #include "bme280.h" #include + +void uart_init(void) { + // Set baud rate + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; + + // Don't use double rate + UCSR0A &= ~(1 << U2X0); + + // Enable rx and tx + UCSR0B = (1 << TXEN0) | (1 << RXEN0); + + // Set frame format: 8-N-1 + UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); +} + +void uart_putchar(char c) { + while(!(UCSR0A & (1 << UDRE0))); + + UDR0 = c; +} + int main(void) { // make the LED pin an output for PORTB5 @@ -24,12 +50,14 @@ int main(void) pressure = bme280_readPressure(0); humidity = bme280_readHumidity(0); + uart_init(); while (1) { _delay_ms(1000); + uart_putchar('!'); - printf("Temp: %f\tPressure: %f\tHumidity: %f\n", temp, pressure, humidity); + //printf("Temp: %f\tPressure: %f\tHumidity: %f\n", temp, pressure, humidity); // toggle the LED PORTB ^= 1 << 5;