void EEPROM::ToRam(void * startAddr, void * endAddr, int eeStart) { //Copy from EEPROM beginning at eeStart address to startAddr..endAddr in main RAM. unsigned char * addr; SetAddr(eeStart); //Set EEPROM's address pointer i2cStart(); SendByte(0xA1); //EEPROM I2C address + read operation if(startAddr == endAddr) { addr = (unsigned char *)startAddr; } else { addr = (unsigned char *)startAddr; while( addr != ((unsigned char *)endAddr) ) //Main RAM index startAddr to endAddr { *addr++ = GetByte(); //GetByte byte from EEPROM & copy to RAM SendAck(ACK); //Acknowledge byte received } } *addr = GetByte(); //GetByte byte from EEPROM & copy to RAM SendAck(NACK); i2cRelease(); //Stop sequential read }
void EEPROM::FromRam(void * startAddr, void * endAddr, int eeStart) { unsigned char * addr; unsigned char * page; //Copy startAddr..endAddr from main RAM to EEPROM beginning at eeStart address. addr = (unsigned char *)startAddr; //Initialize main RAM index int eeAddr = eeStart; //Initialize EEPROM index do { page = addr+64 - eeAddr%64; //Find next EEPROM page boundary if( page > (unsigned char*)endAddr+1) { page = (unsigned char *)endAddr+1; } SetAddr(eeAddr); //Give EEPROM starting address do { //Bytes -> EEPROM until page boundary SendByte(*addr++); } while(addr != page); i2cRelease(); //From 24LC256's page buffer -> EEPROM eeAddr = (int)addr - (int)startAddr+eeStart; //Next EEPROM starting address } while( addr <= endAddr ); //Quit when RAM index > end address }
TwoWire::~TwoWire() { flush(); if(i2c) { i2cRelease(i2c); i2c=NULL; } }
static portTASK_FUNCTION(readTemp, args) { while (1) { i2cAcquire(DS3232_I2C_ADDRESS); i2cSend(0x11); unsigned char tempMSB = i2cReceive(I2C_ACK); unsigned char tempLSB = i2cReceive(I2C_NACK) >> 6; i2cRelease(); printf("Temp %d.%d C\n", tempMSB, 25 * tempLSB); vTaskDelay(1000 / portTICK_PERIOD_MS); } }