Skip to content

Commit

Permalink
Merge pull request #12 from COVID-19-electronic-health-system/devel
Browse files Browse the repository at this point in the history
Enables Bluetooth functionality
  • Loading branch information
k105la authored Jun 6, 2020
2 parents f7b78a0 + 9b234b5 commit 0a431e0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions board/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion board/driver/led.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <avr/io.h>
#include <util/delay.h>
#define STATUS_LED PA1
#define STATUS_LED PB0

void ledInit(void);
void idle_blink(unsigned int period);
Expand Down
9 changes: 6 additions & 3 deletions board/driver/usart.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#define CLKS 1000000
#define FOCS 2000000
#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);
int print(char c, FILE *stream);

11 changes: 8 additions & 3 deletions board/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include "driver/usart.h"
#include "driver/led.h"

static FILE mystdout = FDEV_SETUP_STREAM(print, NULL, _FDEV_SETUP_RW);

int main(void) {
ledInit();
while(1) {
idle_blink(500); // Blinks PanFLUte's on-board LED
usartInit(MYUBRR);
stdout = &mystdout;
while(1) {
printf("%d\n", 21 + 79);
delay_ms(1000);
}
return 0;
}
8 changes: 8 additions & 0 deletions board/usart/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand All @@ -25,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;
}

0 comments on commit 0a431e0

Please sign in to comment.