From 11b172359605bced1ae246a6121db986952a123d Mon Sep 17 00:00:00 2001 From: akilhylton Date: Fri, 5 Jun 2020 23:00:19 -0400 Subject: [PATCH 1/4] Switched status pin for later usage --- board/driver/led.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/driver/led.h b/board/driver/led.h index a4e7bdc..be3e173 100644 --- a/board/driver/led.h +++ b/board/driver/led.h @@ -1,6 +1,6 @@ #include #include -#define STATUS_LED PA1 +#define STATUS_LED PB0 void ledInit(void); void idle_blink(unsigned int period); From ec2d2a460dcec0514e14ab4f6dcb7db1b1607b7c Mon Sep 17 00:00:00 2001 From: akilhylton Date: Fri, 5 Jun 2020 23:05:45 -0400 Subject: [PATCH 2/4] Doubled the USART Transmission Speed --- board/driver/usart.h | 5 ++--- board/main.c | 7 +++++-- board/usart/usart.c | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/board/driver/usart.h b/board/driver/usart.h index e541499..10c7c13 100644 --- a/board/driver/usart.h +++ b/board/driver/usart.h @@ -1,8 +1,7 @@ #include -#define CLKS 1000000 +#define FOCS 1000000 #define BAUD 9600 -#define MYUBRR ((CLKS/16*BAUD) - 1) - +#define MYUBRR FOCS/16/BAUD-1 void usartInit(unsigned int ubrr); void usartTransmit(unsigned char data); unsigned char usartReceive(void); diff --git a/board/main.c b/board/main.c index bfca054..bb77ab5 100644 --- a/board/main.c +++ b/board/main.c @@ -1,9 +1,12 @@ +#include "driver/usart.h" #include "driver/led.h" int main(void) { ledInit(); - while(1) { - idle_blink(500); // Blinks PanFLUte's on-board LED + usartInit(12); + while(1) { + usartTransmit(10); + delay_ms(100); } return 0; } diff --git a/board/usart/usart.c b/board/usart/usart.c index 6c7ed85..e9637c6 100644 --- a/board/usart/usart.c +++ b/board/usart/usart.c @@ -8,6 +8,7 @@ void usartInit(unsigned int ubrr) { UCSR0B = ((1 << RXEN0) | (1 << TXEN0)); /* Set frame format: 8data, 1 stop bit */ UCSR0C = ((1 << UCSZ00) | (1 << UCSZ01)); + UCSR0A = (1 << U2X0); // Double the USART Transmission Speed } From b74a413cc5c8ec3587e9df3fb3c3fb044d084bbb Mon Sep 17 00:00:00 2001 From: akilhylton Date: Sat, 6 Jun 2020 03:37:41 -0400 Subject: [PATCH 3/4] Doubled the clock speed for proper ubbr output --- board/driver/usart.h | 2 +- board/main.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/board/driver/usart.h b/board/driver/usart.h index 10c7c13..122a3cf 100644 --- a/board/driver/usart.h +++ b/board/driver/usart.h @@ -1,5 +1,5 @@ #include -#define FOCS 1000000 +#define FOCS 2000000 #define BAUD 9600 #define MYUBRR FOCS/16/BAUD-1 void usartInit(unsigned int ubrr); diff --git a/board/main.c b/board/main.c index bb77ab5..adf1898 100644 --- a/board/main.c +++ b/board/main.c @@ -2,10 +2,9 @@ #include "driver/led.h" int main(void) { - ledInit(); - usartInit(12); + usartInit(MYUBRR); while(1) { - usartTransmit(10); + usartTransmit(54); delay_ms(100); } return 0; From 9b234b52cdf1af18537a1cd85604b4f4ed92319f Mon Sep 17 00:00:00 2001 From: akilhylton Date: Sat, 6 Jun 2020 17:17:12 -0400 Subject: [PATCH 4/4] Add ability to send integer over usart --- board/Makefile | 4 ++-- board/driver/usart.h | 4 ++++ board/main.c | 7 +++++-- board/usart/usart.c | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/board/Makefile b/board/Makefile index 89a5978..5d23fe3 100644 --- a/board/Makefile +++ b/board/Makefile @@ -3,7 +3,7 @@ PROGRAMMER=atmelice_isp F_CPU=1000000 CC=avr-gcc OBJCOPY=avr-objcopy -CFLAGS=-Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} +CFLAGS=-Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -Wl,-u,vfprintf TARGET=main SRC=main.c ADC_LIB=adc/adc.c @@ -12,7 +12,7 @@ MPX_LIB=mpx5100/mpx5100.c LED_LIB=led/led.c all: - ${CC} ${CFLAGS} ${SRC} ${ADC_LIB} ${USART_LIB} ${MPX_LIB} ${LED_LIB} -o firmware/${TARGET}.bin -std=c99 + ${CC} ${CFLAGS} ${SRC} ${ADC_LIB} ${USART_LIB} ${MPX_LIB} ${LED_LIB} -o firmware/${TARGET}.bin -std=c99 ${OBJCOPY} -j .text -j .data -O ihex firmware/${TARGET}.bin firmware/${TARGET}.hex flash: diff --git a/board/driver/usart.h b/board/driver/usart.h index 122a3cf..a6ed3ba 100644 --- a/board/driver/usart.h +++ b/board/driver/usart.h @@ -1,3 +1,5 @@ +#include +#include #include #define FOCS 2000000 #define BAUD 9600 @@ -5,3 +7,5 @@ void usartInit(unsigned int ubrr); void usartTransmit(unsigned char data); unsigned char usartReceive(void); +int print(char c, FILE *stream); + diff --git a/board/main.c b/board/main.c index adf1898..0e67f1e 100644 --- a/board/main.c +++ b/board/main.c @@ -1,11 +1,14 @@ #include "driver/usart.h" #include "driver/led.h" +static FILE mystdout = FDEV_SETUP_STREAM(print, NULL, _FDEV_SETUP_RW); + int main(void) { usartInit(MYUBRR); + stdout = &mystdout; while(1) { - usartTransmit(54); - delay_ms(100); + printf("%d\n", 21 + 79); + delay_ms(1000); } return 0; } diff --git a/board/usart/usart.c b/board/usart/usart.c index e9637c6..e7aa912 100644 --- a/board/usart/usart.c +++ b/board/usart/usart.c @@ -26,3 +26,10 @@ unsigned char usartReceive(void) { /* Get and return received data from buffer */ return UDR0; } + +int print(char c, FILE *stream) { + while((UCSR0A & (1 << UDRE0)) == 0); + UDR0 = c; + return 0; +} +