0

PIC24F16KA101 MCU の内部メモリとやり取りしようとしています。プロジェクトで使用されているこのサイトのデータシートとディスカッション(非常に役立つサンプルコードを提供しています) を読んだ後、プログラムの下にコードを配置すると、同じ値を正常に読み取ることができるため、問題なく動作します以前書いた。ただし、書き込み後に MCU を取り外し、EEPROM の読み取りのみを実行すると、書き込まれた値が返されません。ここで何が問題になる可能性がありますか?. 書き込みと読み取りは正常に実行できるのに、電源をオフにすると読み取りができないのはなぜですか? ダミアンを助けてくれてありがとう

int __attribute__ ((space(eedata))) ee_addr;
void EepSetup();
void EepErase(void);
int EepWrite(int index, int data);
int EepRead(int index);

int main(int argc, char** argv) 
{
    unsigned int data = 123;
    unsigned int data_read = 0;

    Init_UART1();
    UART1WriteString("START EEPROM PROGRAM \n");
    EepSetup();
    UART1WriteString("WRITING DATA TO MEMORY \n");
    EepWrite(1,data);

    //if the code works, just comment the upper section and read eeprom after
    //disconecting the power source
    UART1WriteString("READING DATA FROM MEMORY \n");
    data_read = EepRead(1);
    UART1WriteString("Value Read: ");
    UART1WriteInt(data_read,16);
    UART1WriteString("\n");
    __delay_ms(1000);
    return (EXIT_SUCCESS);
}
void EepSetup(){
    //Disable Interrupts For 5 instructions
    asm volatile("disi #5");
    //Issue Unlock Sequence
    asm volatile("mov #0x55, W0 \n"
    "mov W0, NVMKEY \n"
    "mov #0xAA, W1 \n"
    "mov W1, NVMKEY \n");
}
void EepErase(void) {
    NVMCON = 0x4050;            // Set up NVMCON to bulk erase the data EEPROM
    asm volatile ("disi #5");   // Disable Interrupts For 5 Instructions
    __builtin_write_NVM();      // Issue Unlock Sequence and Start Erase Cycle
    while(_WR)
    ;
}

int EepRead(int index){
    unsigned int offset;

    TBLPAG = __builtin_tblpage(&ee_addr);    // Initialize EE Data page pointer
    offset = __builtin_tbloffset(&ee_addr);  // Initizlize lower word of address
    offset += index * sizeof(int);
    return __builtin_tblrdl(offset);    // read EEPROM data
}

int EepWrite(int index, int data){
    unsigned int offset;
    NVMCON = 0x4004;    // Set up NVMCON to erase one word of data EEPROM
    TBLPAG = __builtin_tblpage(&ee_addr);    // Initialize EE Data page pointer
    offset = __builtin_tbloffset(&ee_addr);  // Initizlize lower word of address
    offset += index * sizeof(int);
    __builtin_tblwtl(offset, data);
    asm volatile ("disi #5");   // Disable Interrupts For 5 Instructions
    __builtin_write_NVM();      // Issue Unlock Sequence and Start Erase Cycle
    while(_WR);
    return (EXIT_SUCCESS);
}
4

1 に答える 1