Merge remote-tracking branch 'origin/main' into voltage-reading
This commit is contained in:
commit
d8bd6917f6
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,3 +27,5 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.zip
|
*.zip
|
||||||
*.pdf
|
*.pdf
|
||||||
|
/prosjekt.X/build/
|
||||||
|
/prosjekt.X/dist/
|
||||||
@ -5,7 +5,6 @@
|
|||||||
* Created on March 6, 2024, 12:34 PM
|
* Created on March 6, 2024, 12:34 PM
|
||||||
*/
|
*/
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
#define F_CPU 4000000UL
|
|
||||||
#define RTC_PERIOD (511)
|
#define RTC_PERIOD (511)
|
||||||
#define DELAY_TIME 1000
|
#define DELAY_TIME 1000
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
@ -13,12 +12,25 @@
|
|||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
#define F_CPU 4E6
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "uart.h"
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
init_uart((uint16_t)9600);
|
||||||
|
stdout = &USART_stream;
|
||||||
|
|
||||||
void sensor_init(void) {
|
void sensor_init(void) {
|
||||||
/* Disable digital input buffer */
|
/* Disable digital input buffer */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
printf("Hello, world!\n");
|
||||||
|
_delay_ms(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADC0_init(void) {
|
void ADC0_init(void) {
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
<logicalFolder name="HeaderFiles"
|
<logicalFolder name="HeaderFiles"
|
||||||
displayName="Header Files"
|
displayName="Header Files"
|
||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
|
<itemPath>uart.h</itemPath>
|
||||||
<itemPath>header.h</itemPath>
|
<itemPath>header.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ExternalFiles"
|
<logicalFolder name="ExternalFiles"
|
||||||
@ -19,6 +20,7 @@
|
|||||||
displayName="Source Files"
|
displayName="Source Files"
|
||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>main.c</itemPath>
|
<itemPath>main.c</itemPath>
|
||||||
|
<itemPath>uart.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<projectmakefile>Makefile</projectmakefile>
|
<projectmakefile>Makefile</projectmakefile>
|
||||||
|
|||||||
25
prosjekt.X/uart.c
Normal file
25
prosjekt.X/uart.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
void init_uart(uint16_t baud) {
|
||||||
|
// Configure UART pin directions
|
||||||
|
PORTB.DIR &= ~PIN1_bm;
|
||||||
|
PORTB.DIR |= PIN0_bm;
|
||||||
|
// Set the baudrate
|
||||||
|
USART3.BAUD = (uint16_t)USART3_BAUD_RATE(baud);
|
||||||
|
// Enable UART TX & RX
|
||||||
|
USART3.CTRLB |= USART_TXEN_bm;
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART3_sendChar(char c) {
|
||||||
|
// Hold the code while the UART is not ready to send
|
||||||
|
while (!(USART3.STATUS & USART_DREIF_bm)) { ; }
|
||||||
|
// UART is ready, send the character.
|
||||||
|
USART3.TXDATAL = c;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int USART3_printChar(char c, FILE *stream) {
|
||||||
|
USART3_sendChar(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
40
prosjekt.X/uart.h
Normal file
40
prosjekt.X/uart.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* File: uart.h
|
||||||
|
* Author: Sebastian H. Gabrielli
|
||||||
|
*
|
||||||
|
* Created on March 6, 2024, 3:19 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UART_H
|
||||||
|
#define UART_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef F_CPU
|
||||||
|
#define F_CPU 4E6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
|
||||||
|
|
||||||
|
// Initialize the USART3 controller
|
||||||
|
void init_uart(uint16_t baud);
|
||||||
|
|
||||||
|
// Send a single character over UART
|
||||||
|
void USART3_sendChar(char c);
|
||||||
|
|
||||||
|
// Send a string of characters over UART
|
||||||
|
int USART3_printChar(char c, FILE *stream);
|
||||||
|
|
||||||
|
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* UART_H */
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user