EEPROM write/read für PIC18F27Q84

OP #7673133
Lesenswert?

Hallo,

ich wollte in einem Projekt einen Marker setzen, der auch einen Stromreset übersteht, dafür wollte ich in den EEPROM schreiben mit:

DATAEE_WriteByte(0x2, 0xAB);

Dazu gehört dann eine IF clause, bei der das gleiche Byte wieder ausgelesen wird:

if (DATAEE_ReadByte(0x2)==0xAB)

Das funktioniert bei mir nicht. Mein Wissen ist aber auch sehr begrenzt. Hat jemand eine Idee woran es liegen könnte?

Danke schonmal vorab.

Chris

OP #7673341
Lesenswert?

Danke für die Rückmeldung.

Der Teil zum Schreiben sieht so aus:

switch(funcRes) { case STATE_RUNNING: break; case STATE_ERROR: InitNextStage(SEQ_CONNECTION_REQUEST); break; case STATE_OK: DATAEE_WriteByte(0x2, 0xAB); InitNextStage(SEQ_IDLE); res = 1; break;}

Der zum Auslesen so:

if (emul_init_seq==0 && ig_rise_count>=1) { if (DATAEE_ReadByte(0x2)==0xAB) emul_init_seq = 1; if (emul_init_seq==2) { emul_init_seq = 0; // reset flag for sending init sequence ig_rise_count = 0; coding_message_type = 0; InitSendMsgSeq(); } else emul_init_seq = codingSequence(&rcvdMsg, msgCnt?1:0);

Ja, stammt aus MCC und einem Bsp. aus der memory.h

OP #7674433
Lesenswert?

Die Funktionen sind durch MCC generiert:

void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData) { uint8_t GIEBitValue = INTCON0bits.GIE;

1
//Set NVMADR with the target word address (0x380000 - 0x3803FF)
2
NVMADRU = 0x38;
3
NVMADRH = (uint8_t) ((bAdd & 0xFF00) >> 8);
4
NVMADRL = (uint8_t) (bAdd & 0x00FF);
5

6
//Load NVMDATL with desired byte
7
NVMDATL = bData;
8

9
//Set the NVMCMD control bits for DFM Byte Write operation
10
NVMCON1bits.NVMCMD = 0b011;
11

12
//Disable all interrupts
13
INTCON0bits.GIE = 0;
14

15
//Perform the unlock sequence and start Page Erase
16
NVMLOCK = 0x55;
17
NVMLOCK = 0xAA;
18

19
//Start DFM write and wait for the operation to complete
20
NVMCON0bits.GO = 1;
21
while (NVMCON0bits.GO);
22

23
//Restore all the interrupts
24
INTCON0bits.GIE = GIEBitValue;
25

26
//Set the NVMCMD control bits for Word Read operation to avoid accidental writes
27
NVMCON1bits.NVMCMD = 0b000;

}

uint8_t DATAEE_ReadByte(uint16_t bAdd) { //Set NVMADR with the target word address (0x380000 - 0x3803FF) NVMADRU = 0x38; NVMADRH = (uint8_t) ((bAdd & 0xFF00) >> 8); NVMADRL = (uint8_t) (bAdd & 0x00FF);

1
//Set the NVMCMD control bits for DFM Byte Read operation
2
NVMCON1bits.NVMCMD = 0b000;
3
NVMCON0bits.GO = 1;
4

5
return NVMDATL;

}

Die Zelle sollte erst wenige Male beschrieben worden sein.

OP #7674458
Lesenswert?

Hab es jetzt so geändert. Geht aber leider immer noch nicht:

uint8_t DATAEE_ReadByte(uint16_t bAdd) { //Set NVMADR with the target word address (0x380000 - 0x3803FF) NVMADRU = 0x38; NVMADRH = (uint8_t) ((bAdd & 0xFF00) >> 8); NVMADRL = (uint8_t) (bAdd & 0x00FF);

1
//Set the NVMCMD control bits for DFM Byte Read operation
2
NVMCON1bits.NVMCMD = 0b000;
3
NVMCON0bits.GO = 1;
4
while (NVMCON0bits.GO);
5

6
return NVMDATL;

}

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