Hallo,
ich habe folgendes Problem:
In unten stehendem Code-Ausschnitt soll eine Variable im EEPROM angelegt
und initialisiert werden. Leider funktioniert genau das nicht.
Die Variable erhalt weder ihre Init-Werte, noch läuft das Programm
danach sauber weiter.
Ich vermute, mein Programm hängt sich auf, weil unzulässige Werte von
der EEPROM_READ_BLOCK zurückgegeben werden, die den ATMega zu Absturz
bringen.
Kommentiere ich die Zeile mit EEPROM_READ_BLOCK aus, dann läuft mein
Programm wie erwartet.
Ich vermute, dass die Variable im EEPROM schon falsch angelegt wird. Hat
jemand Erfahrung mit Variablen im EEPROM und dem mySmartUSBlight (im
Modus STK500)? FW ist aktuell laut myAVR.
Meine RS232 Ausgabe lautet:
Reading EEPROM...
383
0
Attentuation = 0
1 | volatile mcSettings EEMEM eeSet = {.channelIndex = 0, .muteL = 1, .muteR = 0, .attentuations = {61, 61}, .brightness = 0, .eepromStartAddress = 0, .eepromWriteCycles = 0};
|
2 | volatile mcSettings set_ram; // once filled with EEPROM values and cyclic written to EEPROM
|
3 |
|
4 |
|
5 | volatile uint8_t attentuation;
|
6 |
|
7 |
|
8 | int main (void){
|
9 | cli();
|
10 | usart_puts("\n\rReading EEPROM... \n\r");
|
11 | usart_puti(&set_ram);
|
12 | usart_puts("\n\r");
|
13 | usart_puti(&eeSet);
|
14 | usart_puts("\n\r");
|
15 | eeprom_read_block((void*)&set_ram, (void*)&eeSet, sizeof(mcSettings));
|
16 | //eeprom_busy_wait();
|
17 |
|
18 | attentuation = set_ram.attentuations[set_ram.channelIndex];
|
19 |
|
20 | sei();
|
21 |
|
22 | while(1){
|
23 | _delay_ms(300);
|
24 | PORTC ^= _BV(LED1);
|
25 | //OCR0B = 0x100F;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | usart_puts("Attentuation = ");
|
31 | unsigned char buffer[4];
|
32 | itoa(attentuation, &buffer, 10);
|
33 | usart_puts(buffer);
|
34 | usart_puts("\n\r");
|
35 | }
|
36 | }
|
37 | // USART
|
38 | void usartInit(uint8_t ubrr){
|
39 | //Set baud rate
|
40 | UBRR0H = (unsigned char)(ubrr>>8);
|
41 | UBRR0L = (unsigned char)ubrr;
|
42 | //Enable receiver and transmitter
|
43 | UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
|
44 | //Set frame format: 8data, 1stop bit
|
45 | UCSR0C = ((1 << UCSZ01)|(1 << UCSZ00)); // Asynchron 8N1
|
46 | }
|
47 | unsigned char usart_receive( void )
|
48 | {
|
49 | while ( !(UCSR0A & (1<<RXC0)) ) // Wait for data to be received
|
50 | ;
|
51 | return UDR0;
|
52 | }
|
53 |
|
54 | void usart_puts(const char str[]){
|
55 | int i =0;
|
56 | while (str[i] != 0x00){
|
57 | while (!( UCSR0A & (1<<UDRE0))); // Wait for empty transmit buffer
|
58 | UDR0 = (str[i]);
|
59 | i++;
|
60 | }
|
61 | }
|