/* * File: main.c * Author: Sebastian H. Gabrielli * * Created on March 6, 2024, 12:34 PM */ /* * File: main.c * Author: athamantis * * Created on 01 March 2024, 10:34 */ #include "eeprom.h" #include #include #include #include #define F_CPU 4E6 #include #include #include #define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5) #include // Init UART comunication void USART3_init(void) { // Enable resiver pin PORTB.DIR &= ~PIN1_bm; // Enable sender pin PORTB.DIR |= PIN0_bm; USART3.BAUD = (uint16_t) USART3_BAUD_RATE(115200); USART3.CTRLB |= USART_TXEN_bm; // Enabled in the USART register USART3.CTRLB |= USART_RXEN_bm; } // Use printline __________________________ static void USART3_sendChar(char c) { while (!(USART3.STATUS & USART_DREIF_bm)) { ; } USART3.TXDATAL = c; } static int USART3_printChar(char c, FILE *stream) { USART3_sendChar(c); return 0; } static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE); uint8_t USART3_read() { while (!(USART3.STATUS & USART_RXCIF_bm)) { ; } return USART3.RXDATAL; } /* * make a struct * a space is reserved for that struct * make a function that write the struct to the space * * a running counter for where the fanspeed data should be set * make a function that write the mesured fanSpeed * * read the memory for the struct * read the memory for the fanspeed */ void main() { USART3_init(); stdout = &USART_stream; config_t fanController; fanController.fanSpeed = 8; while(1){ printf("in loop\n"); printf("Write the struct \n"); WriteStructInEEPROM(fanController); printf("Read struct\n"); config_t recivedFancontroller = ReadStructInEEPROM(); printf("writing in eeprom\n"); WriteFanSpeedInEEPROM(2); WriteFanSpeedInEEPROM(3); WriteFanSpeedInEEPROM(5); printf("reading from eeprom\n"); ReadFanSpeedInfo(); _delay_ms(500); } }