2

The main function I'm having a problem with is where I'm writing a value to external EEPROM. I clear the EEPROM, then write my value to it, waiting 100ms afterwards.

#define BAUD_RATE (int)100e3 // the standard baud rate
...
void initIR(){
    bcm2835_init();
    bcm2835_i2c_begin();
    bcm2835_i2c_set_baudrate((int)BAUD_RATE);
    bcm2835_i2c_setSlaveAddress(0x5a);
}
void writeConfig(){
    unsigned char comm = 0x25; // the command to send. access EEPROM
    unsigned char * write = (unsigned char *)malloc(sizeof(unsigned char) * 9); 
    unsigned char * clear = (unsigned char *)malloc(sizeof(unsigned char) * 9);

    write[0] = 0x25; write[1] = 0x74; write[2] = 0xb4; write[3] = 0x70;
    clear[0] = 0x25; clear[1] = 0x00; clear[2] = 0x00; clear[3] = 0x83;

    /*bcm2835_i2c_begin();*/
    int c = bcm2835_i2c_write(clear, 3);
    waitMillis(100);
    int w = bcm2835_i2c_write(write, 3);
    waitMillis(100);


    printf("c: %d, w: %d\n", c, w);
    free(clear);
    free(write);
}

Other I2C functions work, so I know my baud rate and slave address are correct. The function bcm2835_i2c_write returns...

| Return value | Message                        |
|:------------:|:------------------------------:|
| 0            | Message received OK            |
| 1            | Received NACK                  |
| 2            | Received clock stretch timeout |
| 3            | Not all data sent/received     |

When I don't include the PEC, I receive a 0, but the value in EEPROM doesn't change (and as expected). When I include the PEC, I receive a 1, and the value in EEPROM doesn't change.

How do I fix write to EEPROM?

1

Turns out turning the device off then on after writing to the EEPROM will fix this error. Apparently the EEPROM is only loaded on startup (at least for this device).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.