Skip to content

Instantly share code, notes, and snippets.

@dancollins
Created September 29, 2012 05:58
Show Gist options
  • Save dancollins/3803317 to your computer and use it in GitHub Desktop.
Save dancollins/3803317 to your computer and use it in GitHub Desktop.
This is the EEPROM read function. Output is: https://gist.github.com/3803316
void ee_read(char * buf, unsigned int addr, unsigned int len) {
unsigned int i;
sprintf(bf1, "Starting EEPROM read of %u bytes.\r\n", len);
debugr(bf1);
IdleI2C1();
StartI2C1();
WriteI2C1(EE_ADDR | EE_W);
IdleI2C1();
WriteI2C1((unsigned char)addr>>8);
IdleI2C1();
WriteI2C1((unsigned char)addr&0xFF);
IdleI2C1();
RestartI2C1();
WriteI2C1(EE_ADDR | EE_R);
IdleI2C1();
for (i=0; i<len; i++) {
buf[i] = ReadI2C1();
sprintf(bf1, "Addr: %u Byte: %c\r\n", addr, buf[i]);
debugr(bf1);
addr++;
IdleI2C1();
if (i == len-1) {
NotAckI2C1();
} else {
AckI2C1();
}
}
StopI2C1();
debug("\r\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment