From c48f87bcea7902ec76ab9c7be056455a4f556fab Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 13 Mar 2024 10:34:46 +0100 Subject: [PATCH] write to update, and uart away. --- prosjekt.X/eeprom.c | 15 ++---- prosjekt.X/main.c | 67 ------------------------- prosjekt.X/nbproject/configurations.xml | 3 ++ 3 files changed, 7 insertions(+), 78 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 5d9f39d..2cc7d24 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -11,9 +11,6 @@ uint8_t EEMEM startAddressFan2 = 0x60; uint8_t EEMEM currentAddressFan1 = 0x30; uint8_t EEMEM currentAddressFan2 = 0x60; -// Checks if its written a struct in the memmory space. -bool alreadyWrittenABlock = false; - // Checks if the EEPROM memory is ready to be written in. void checkEEpromIsReady(){ while(1){ @@ -39,12 +36,8 @@ void WriteStructInEEPROM(config_t writeStruct){ checkEEpromIsReady(); - if (alreadyWrittenABlock){ - eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); - }else{ - eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize); - alreadyWrittenABlock = true; - } + eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); + } // Reads the memory block at the address 0x00 @@ -68,10 +61,10 @@ void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){ checkEEpromIsReady(); if (data == 1){ - eeprom_write_byte(currentAddressFan1, dataPoint); + eeprom_update_byte(currentAddressFan1, dataPoint); currentAddressFan1++; } else if (data == 2){ - eeprom_write_byte(currentAddressFan2, dataPoint); + eeprom_update_byte(currentAddressFan2, dataPoint); currentAddressFan2++; } else{ // error??? diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index dedbf52..f22e602 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -23,77 +23,10 @@ #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); } } diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 917cf54..808b914 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -145,6 +145,9 @@ + + +