ATXMEGA128A1-AU und C

Gast #1438507
Lesenswert?

Hallo,

ich habe folgenden C-Code, den ich compiliert habe und dann mit dem 
Deassembler vom AVR-Studio angezeigt habe.

Ich finde das merkwürdig, was der Compiler da erzeugt und kann nach 
meinem Verständnis eigentlich gar nicht funktionieren:
1
279:        sbi(SPIF_CTRL, SPI_MASTER_bm);
2
+0000058C:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
3
+0000058E:   93800BC0    STS       0x0BC0,R24     Store direct to data space
4
281:        cbi(SPIF_CTRL, SPI_MODE0_bm);
5
+00000590:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
6
+00000592:   7E8F        ANDI      R24,0xEF       Logical AND with immediate
7
+00000593:   93800BC0    STS       0x0BC0,R24     Store direct to data space
8
282:        cbi(SPIF_CTRL, SPI_MODE1_bm);
9
+00000595:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
10
+00000597:   93800BC0    STS       0x0BC0,R24     Store direct to data space
11
284:        cbi(SPIF_CTRL, SPI_DORD_bm);
12
+00000599:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
13
+0000059B:   93800BC0    STS       0x0BC0,R24     Store direct to data space
14
286:        cbi(SPIF_CTRL, SPI_PRESCALER0_bm);
15
+0000059D:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
16
+0000059F:   7F8D        ANDI      R24,0xFD       Logical AND with immediate
17
+000005A0:   93800BC0    STS       0x0BC0,R24     Store direct to data space
18
287:        cbi(SPIF_CTRL, SPI_PRESCALER1_bm);
19
+000005A2:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
20
+000005A4:   7F8B        ANDI      R24,0xFB       Logical AND with immediate
21
+000005A5:   93800BC0    STS       0x0BC0,R24     Store direct to data space
22
288:        sbi(SPIF_CTRL, SPI_CLK2X_bm);
23
+000005A7:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
24
+000005A9:   93800BC0    STS       0x0BC0,R24     Store direct to data space
25
290:        sbi(SPIF_CTRL, SPI_ENABLE_bm);
26
+000005AB:   91800BC0    LDS       R24,0x0BC0     Load direct from data space
27
+000005AD:   93800BC0    STS       0x0BC0,R24     Store direct to data space

Und das funktioniert anscheinend auch nicht:
1
291:        SPIF_CTRL = (1<<SPI_MASTER_bm) | (1<<SPI_CLK2X_bm) | (1<<SPI_ENABLE_bm);
2
+0000058C:   92100BC0    STS       0x0BC0,R1      Store direct to data space
3
153:

Aber so geht es:
1
291:        SPIF_CTRL = 0b11010000;//(1<<SPI_MASTER_bm) | (1<<SPI_CLK2X_bm) | (1<<SPI_ENABLE_bm); 
2
+0000058C:   ED80        LDI       R24,0xD0       Load immediate
3
+0000058D:   93800BC0    STS       0x0BC0,R24     Store direct to data space

Ich hab das AVR-Studio Version 4.17 Build 666 und dazu WinAVR 20090313.
Persönliche Seite #1441407
Lesenswert?

Wie schon angedeutet ist doch völlig klar, warum das nicht funktioniert.

Die Bitmasken sind schon die geshifteten Werte. Wenn du dann ne 1 zum 
Beispiel noch mal um 128 bzw. 0x80 shiftest, dann passt das nicht mehr 
in einen Integer. Das sollte dir der Compiler auch als Warnung ausgeben, 
die du scheinbar ignoriert hast.

Abhilfe, wie schon gesagt, statt _bm Konstanten _bp hinten dranhängen.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren