write to update, and uart away.
This commit is contained in:
parent
6d6ea9606e
commit
c48f87bcea
@ -11,9 +11,6 @@ uint8_t EEMEM startAddressFan2 = 0x60;
|
|||||||
uint8_t EEMEM currentAddressFan1 = 0x30;
|
uint8_t EEMEM currentAddressFan1 = 0x30;
|
||||||
uint8_t EEMEM currentAddressFan2 = 0x60;
|
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.
|
// Checks if the EEPROM memory is ready to be written in.
|
||||||
void checkEEpromIsReady(){
|
void checkEEpromIsReady(){
|
||||||
while(1){
|
while(1){
|
||||||
@ -39,12 +36,8 @@ void WriteStructInEEPROM(config_t writeStruct){
|
|||||||
|
|
||||||
checkEEpromIsReady();
|
checkEEpromIsReady();
|
||||||
|
|
||||||
if (alreadyWrittenABlock){
|
|
||||||
eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize);
|
eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize);
|
||||||
}else{
|
|
||||||
eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize);
|
|
||||||
alreadyWrittenABlock = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the memory block at the address 0x00
|
// Reads the memory block at the address 0x00
|
||||||
@ -68,10 +61,10 @@ void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){
|
|||||||
|
|
||||||
checkEEpromIsReady();
|
checkEEpromIsReady();
|
||||||
if (data == 1){
|
if (data == 1){
|
||||||
eeprom_write_byte(currentAddressFan1, dataPoint);
|
eeprom_update_byte(currentAddressFan1, dataPoint);
|
||||||
currentAddressFan1++;
|
currentAddressFan1++;
|
||||||
} else if (data == 2){
|
} else if (data == 2){
|
||||||
eeprom_write_byte(currentAddressFan2, dataPoint);
|
eeprom_update_byte(currentAddressFan2, dataPoint);
|
||||||
currentAddressFan2++;
|
currentAddressFan2++;
|
||||||
} else{
|
} else{
|
||||||
// error???
|
// error???
|
||||||
|
|||||||
@ -23,77 +23,10 @@
|
|||||||
#define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5)
|
#define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5)
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// 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() {
|
void main() {
|
||||||
USART3_init();
|
|
||||||
stdout = &USART_stream;
|
|
||||||
|
|
||||||
config_t fanController;
|
|
||||||
|
|
||||||
fanController.fanSpeed = 8;
|
|
||||||
|
|
||||||
while(1){
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -145,6 +145,9 @@
|
|||||||
<property key="program-the-device-with-default-config-words" value="false"/>
|
<property key="program-the-device-with-default-config-words" value="false"/>
|
||||||
<property key="remove-unused-sections" value="true"/>
|
<property key="remove-unused-sections" value="true"/>
|
||||||
</HI-TECH-LINK>
|
</HI-TECH-LINK>
|
||||||
|
<Tool>
|
||||||
|
<property key="debugoptions.useswbreakpoints" value="true"/>
|
||||||
|
</Tool>
|
||||||
<XC8-CO>
|
<XC8-CO>
|
||||||
<property key="coverage-enable" value=""/>
|
<property key="coverage-enable" value=""/>
|
||||||
<property key="stack-guidance" value="false"/>
|
<property key="stack-guidance" value="false"/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user