Moinsen.
Mal wieder ein Problem.
Für eine Aquariensteuerung (Mehrkanalschaltuhr etc.) schreib ich gerade das Programm. Die Hardware selbst ist noch nicht vorhanden, deshalb teste ich die Funktionen gerade im Simulator des AVR-Studio.
In diesem Programm sollen Werte für die Schaltzeiten im EEPROM abgespeichert werden. Beim Start des Programms sollen die Werte dann in Structs übernommen werden, die im RAM liegen.
Und genau da kommt das Problem: Aus noch unbekannten Gründen wird dort immer 0xFF ausgelesen.
Dabei ist es egal, welche der drei folgenden Aufrufe ich verwende:
Code:
Channel[CH1].TH_Off = EEP_ReadByte(S_T1_OFFH);
Channel[CH1].TH_Off = EEP_T1_OffH;
Channel[CH1].TH_Off = EEP_ReadByte(EEP_T1_OffH);
Ich hab mal die betreffenden Dateien hier angehängt. Das gesamte Projekt liegt in nem .zip-Archiv ebenfalls mit dabei. Nicht wundern über die ganzen anderen "Baustellen".
Sieht hier jemand den Fehler?
Oder ist das wieder eines dieser Dinge, wo der Simulator einfach Mist baut?
EEP.c:
Code:
#include "eep.h"
// EEPROM-Variables
extern stc_TimeChannels Channel[8];
ui8_t EEP_dummy EEMEM = 0xFF; /* avoid Address 0x00 */
ui8_t EEP_T1_OffH EEMEM = 8;
ui8_t EEP_T1_OffM EEMEM = 30;
ui8_t EEP_T1_OnH EEMEM = 20;
ui8_t EEP_T1_OnM EEMEM = 15;
ui8_t EEP_T2_OffH EEMEM = 8;
ui8_t EEP_T2_OffM EEMEM = 0;
ui8_t EEP_T2_OnH EEMEM = 20;
ui8_t EEP_T2_OnM EEMEM = 0;
ui8_t EEP_T3_OffH EEMEM = 8;
ui8_t EEP_T3_OffM EEMEM = 0;
ui8_t EEP_T3_OnH EEMEM = 20;
ui8_t EEP_T3_OnM EEMEM = 0;
ui8_t EEP_T4_OffH EEMEM = 8;
ui8_t EEP_T4_OffM EEMEM = 0;
ui8_t EEP_T4_OnH EEMEM = 20;
ui8_t EEP_T4_OnM EEMEM = 0;
ui8_t EEP_T5_OffH EEMEM = 8;
ui8_t EEP_T5_OffM EEMEM = 0;
ui8_t EEP_T5_OnH EEMEM = 20;
ui8_t EEP_T5_OnM EEMEM = 0;
ui8_t EEP_T6_OffH EEMEM = 8;
ui8_t EEP_T6_OffM EEMEM = 0;
ui8_t EEP_T6_OnH EEMEM = 20;
ui8_t EEP_T6_OnM EEMEM = 0;
ui8_t EEP_T7_OffH EEMEM = 8;
ui8_t EEP_T7_OffM EEMEM = 0;
ui8_t EEP_T7_OnH EEMEM = 20;
ui8_t EEP_T7_OnM EEMEM = 0;
ui8_t EEP_T8_OffH EEMEM = 8;
ui8_t EEP_T8_OffM EEMEM = 0;
ui8_t EEP_T8_OnH EEMEM = 20;
ui8_t EEP_T8_OnM EEMEM = 0;
ui8_t EEP_T1_State EEMEM = 0;
ui8_t EEP_T2_State EEMEM = 0;
ui8_t EEP_T3_State EEMEM = 0;
ui8_t EEP_T4_State EEMEM = 0;
ui8_t EEP_T5_State EEMEM = 0;
ui8_t EEP_T6_State EEMEM = 0;
ui8_t EEP_T7_State EEMEM = 0;
ui8_t EEP_T8_State EEMEM = 0;
// EEPROM Addresses
#define S_T1_OFFH 1
#define S_T1_OFFM 2
#define S_T1_ONH 3
#define S_T1_ONM 4
#define S_T1_STATE 5
void EEP_LoadStartupVariables(void)
{
/* copy variables from EEPROM to RAM */
Channel[CH1].TH_Off = EEP_ReadByte(S_T1_OFFH);
Channel[CH1].TM_Off = EEP_ReadByte(S_T1_OFFM);
Channel[CH1].TH_On = EEP_ReadByte(S_T1_ONH);
Channel[CH1].TM_On = EEP_ReadByte(S_T1_ONM);
Channel[CH1].state = EEP_ReadByte(S_T1_STATE);
Channel[CH2].TH_Off = EEP_T2_OffH;
Channel[CH2].TM_Off = EEP_T2_OffM;
Channel[CH2].TH_On = EEP_T2_OnH;
Channel[CH2].TM_On = EEP_T2_OnM;
Channel[CH2].state = EEP_T2_OffH;
Channel[CH3].TH_Off = EEP_T3_OffH;
Channel[CH3].TM_Off = EEP_T3_OffM;
Channel[CH3].TH_On = EEP_T3_OnH;
Channel[CH3].TM_On = EEP_T3_OnM;
Channel[CH3].state = EEP_T3_OffH;
Channel[CH4].TH_Off = EEP_T4_OffH;
Channel[CH4].TM_Off = EEP_T4_OffM;
Channel[CH4].TH_On = EEP_T4_OnH;
Channel[CH4].TM_On = EEP_T4_OnM;
Channel[CH4].state = EEP_T4_OffH;
Channel[CH5].TH_Off = EEP_T5_OffH;
Channel[CH5].TM_Off = EEP_T5_OffM;
Channel[CH5].TH_On = EEP_T5_OnH;
Channel[CH5].TM_On = EEP_T5_OnM;
Channel[CH5].state = EEP_T5_OffH;
Channel[CH6].TH_Off = EEP_T6_OffH;
Channel[CH6].TM_Off = EEP_T6_OffM;
Channel[CH6].TH_On = EEP_T6_OnH;
Channel[CH6].TM_On = EEP_T6_OnM;
Channel[CH6].state = EEP_T6_OffH;
Channel[CH7].TH_Off = EEP_T7_OffH;
Channel[CH7].TM_Off = EEP_T7_OffM;
Channel[CH7].TH_On = EEP_T7_OnH;
Channel[CH7].TM_On = EEP_T7_OnM;
Channel[CH7].state = EEP_T7_OffH;
Channel[CH8].TH_Off = EEP_T8_OffH;
Channel[CH8].TM_Off = EEP_T8_OffM;
Channel[CH8].TH_On = EEP_T8_OnH;
Channel[CH8].TM_On = EEP_T8_OnM;
Channel[CH8].state = EEP_T8_OffH;
}
ui8_t EEP_ReadByte(ui8_t address)
{
ui8_t retval;
retval = eeprom_read_byte(&address);
return retval;
}
void EEP_WriteByte(ui8_t address, ui8_t value)
{
eeprom_write_byte(&address, value);
}
EEP.h:
Code:
#ifndef _EEP_H_
#define _EEP_H_
#include <avr/io.h>
#include <avr/eeprom.h>
#include "glob_defs.h"
#include "glob_type.h"
//#define EEP_SECT __attribute__ ((section (".eeprom")))
#define CH1 0
#define CH2 1
#define CH3 2
#define CH4 3
#define CH5 4
#define CH6 5
#define CH7 6
#define CH8 7
void EEP_LoadStartupVariables(void);
ui8_t EEP_ReadByte(ui8_t address);
void EEP_WriteByte(ui8_t address, ui8_t value);
#endif
Aufruf in der Main:
Code:
int main(void)
{
// Init system
EEP_LoadStartupVariables(); // Load variables from EEPROM
...
Lesezeichen