Forum: Compiler & IDEs Wieso will das EEPROM nicht?


von Tobias (Gast)


Lesenswert?

Hallo allerseits,

Wahrscheinlich bin ich wiedermal zu blöde, aber dennoch bald am 
durchdrehen.
Wieso zeigt das EEPROM nach diesem Programm 011 022 255 255...
und nicht 011 012 255...?

Ich hab' auch schon andere EEPROM samples aus eigenem, alten Code 
verwendet, der mal gefunzt hat, aber jetzt will alles nicht.
Wo liegt der Hund begraben?

GCC, atmega328p, live und Simulator...

Herzlichen Dank und Gruss, Tobias

8<-----------------------------------

#include <avr/io.h>
#include <avr/eeprom.h>


uint8_t Byte_1_in_EEMEM EEMEM = 11;

uint8_t Byte_2_in_EEMEM EEMEM = 22;

uint8_t blub;

int main(){

    blub = eeprom_read_byte(&Byte_1_in_EEMEM);

  blub++;

  eeprom_write_byte(&Byte_2_in_EEMEM, blub);

  while(1);
}

von Stefan E. (sternst)


Lesenswert?

Je nach Toolchain-Version und Optimierungseinstellungen kann es sein, 
dass das Programm niemals über eeprom_read_byte hinaus kommt, sondern 
dort einen Soft-Reset macht(wegen eines Silicon-Bug). Zeige mal den 
Assembler-Code.

von Tobias (Gast)


Lesenswert?

Danke!

Das ist ja interessant...
Wenn ich das Disassembler- Fenster öffne - tatsächlich findet er da 
etwas nicht, obschon die Pfade richtig gesetzt sind. Mich wundert bloss, 
dass da ohne Warnung compiliert wird.
Ich such' mal weiter...



---- eeprom_test.c 
------------------------------------------------------------------------ 
--------
11:       int main(){
+00000051:   93CF        PUSH      R28            Push register on stack
+00000052:   93DF        PUSH      R29            Push register on stack
+00000053:   B7CD        IN        R28,0x3D       In from I/O location
+00000054:   B7DE        IN        R29,0x3E       In from I/O location
+00000055:   9726        SBIW      R28,0x06       Subtract immediate 
from word
+00000056:   B60F        IN        R0,0x3F        In from I/O location
+00000057:   94F8        CLI                      Global Interrupt 
Disable
+00000058:   BFDE        OUT       0x3E,R29       Out to I/O location
+00000059:   BE0F        OUT       0x3F,R0        Out to I/O location
+0000005A:   BFCD        OUT       0x3D,R28       Out to I/O location
+0000005B:   E080        LDI       R24,0x00       Load immediate
+0000005C:   E090        LDI       R25,0x00       Load immediate
+0000005D:   839E        STD       Y+6,R25        Store indirect with 
displacement
+0000005E:   838D        STD       Y+5,R24        Store indirect with 
displacement
---- C:...\default/c:/winavr-20071221/bin/../avr/include/avr/eeprom.h
193: File not found
+0000005F:   81AD        LDD       R26,Y+5        Load indirect with 
displacement
+00000060:   81BE        LDD       R27,Y+6        Load indirect with 
displacement
+00000061:   940E0081    CALL      0x00000081     Call subroutine
+00000063:   2D80        MOV       R24,R0         Copy register
+00000064:   83BE        STD       Y+6,R27        Store indirect with 
displacement
+00000065:   83AD        STD       Y+5,R26        Store indirect with 
displacement
+00000066:   838C        STD       Y+4,R24        Store indirect with 
displacement
199: File not found
+00000067:   818C        LDD       R24,Y+4        Load indirect with 
displacement
+00000068:   2F88        MOV       R24,R24        Copy register
+00000069:   E090        LDI       R25,0x00       Load immediate
---- eeprom_test.c 
------------------------------------------------------------------------ 
--------
13:           blub = eeprom_read_byte(&Byte_1_in_EEMEM);
+0000006A:   93800100    STS       0x0100,R24     Store direct to data 
space
15:         blub++;
+0000006C:   91800100    LDS       R24,0x0100     Load direct from data 
space
+0000006E:   5F8F        SUBI      R24,0xFF       Subtract immediate
+0000006F:   93800100    STS       0x0100,R24     Store direct to data 
space
17:         eeprom_write_byte(&Byte_2_in_EEMEM, blub);
+00000071:   91200100    LDS       R18,0x0100     Load direct from data 
space
+00000073:   E081        LDI       R24,0x01       Load immediate
+00000074:   E090        LDI       R25,0x00       Load immediate
+00000075:   839A        STD       Y+2,R25        Store indirect with 
displacement
+00000076:   8389        STD       Y+1,R24        Store indirect with 
displacement
+00000077:   832B        STD       Y+3,R18        Store indirect with 
displacement
---- C:\...\default/c:/winavr-20071221/bin/../avr/include/avr/eeprom.h
287: File not found
+00000078:   818B        LDD       R24,Y+3        Load indirect with 
displacement
+00000079:   81A9        LDD       R26,Y+1        Load indirect with 
displacement
+0000007A:   81BA        LDD       R27,Y+2        Load indirect with 
displacement
+0000007B:   2E08        MOV       R0,R24         Copy register
+0000007C:   940E0089    CALL      0x00000089     Call subroutine
+0000007E:   83BA        STD       Y+2,R27        Store indirect with 
displacement
+0000007F:   83A9        STD       Y+1,R26        Store indirect with 
displacement
---- eeprom_test.c 
------------------------------------------------------------------------ 
--------
19:         while(1);
+00000080:   CFFF        RJMP      PC-0x0000      Relative jump
19:         while(1);
+00000081:   99E1        SBIC      0x1C,1         Skip if bit in I/O 
register cleared
+00000082:   CFFE        RJMP      PC-0x0001      Relative jump
+00000083:   BBBF        OUT       0x1F,R27       Out to I/O location
+00000084:   BBAE        OUT       0x1E,R26       Out to I/O location
+00000085:   9AE0        SBI       0x1C,0         Set bit in I/O 
register
+00000086:   9611        ADIW      R26,0x01       Add immediate to word
+00000087:   B20D        IN        R0,0x1D        In from I/O location
+00000088:   9508        RET                      Subroutine return
+00000089:   99E1        SBIC      0x1C,1         Skip if bit in I/O 
register cleared
+0000008A:   CFFE        RJMP      PC-0x0001      Relative jump
+0000008B:   BBBF        OUT       0x1F,R27       Out to I/O location
+0000008C:   BBAE        OUT       0x1E,R26       Out to I/O location
+0000008D:   BA0D        OUT       0x1D,R0        Out to I/O location
+0000008E:   9611        ADIW      R26,0x01       Add immediate to word
+0000008F:   B60F        IN        R0,0x3F        In from I/O location
+00000090:   94F8        CLI                      Global Interrupt 
Disable
+00000091:   9AE2        SBI       0x1C,2         Set bit in I/O 
register
+00000092:   9AE1        SBI       0x1C,1         Set bit in I/O 
register
+00000093:   BE0F        OUT       0x3F,R0        Out to I/O location
+00000094:   9508        RET                      Subroutine return
+00000095:   CFFF        RJMP      PC-0x0000      Relative jump
+00000096:   00FF        ???                      Data or unknown opcode

von Tobias (Gast)


Lesenswert?

Hallo,

Inzwischen gibts nicht mehr so viele Fehlermeldungen, ausser der ersten 
im Assebler- Window. Woher kann diese kommen - und wie ist das mit dem 
Silikon- Bug? Wie finde ich raus, ob dies mein Problem ist?
Die Optimierung hab' ich längst ausgeschaltet.

DANKE!  Tobias

von Stefan E. (sternst)


Lesenswert?

Tobias schrieb:

> Inzwischen gibts nicht mehr so viele Fehlermeldungen, ausser der ersten
> im Assebler- Window. Woher kann diese kommen

Interessiert nicht weiter (jedenfalls nicht in Bezug auf das 
nicht-funktionieren).

> - und wie ist das mit dem
> Silikon- Bug? Wie finde ich raus, ob dies mein Problem ist?

Ist es nicht.

Die Registeradressen stimmen nicht.
Vermutlich hast du nicht den richten Controller eingestellt.

von Tobias (Gast)


Lesenswert?

Danke!
Hab' mir grade selbst geholfen, indem ich die aktuellen c-libraries 
runtergeladen habe. Jetzt funzt alles.
Gruss, Tobias

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.