/** * Gets the software revision of the software in the RLY08 */ unsigned int getRLY08SoftwareRevision() { IdleI2C(); StartI2C(); IdleI2C(); while(I2CCONbits.SEN); // send the address MasterWriteI2C(writeAddr); IdleI2C(); // send the register MasterWriteI2C(RLY08_REGISTER_SOFTWARE_REVISION); IdleI2C(); StopI2C(); IdleI2C(); StartI2C(); while(I2CCONbits.SEN); // send the address again with read bit MasterWriteI2C(readAddr); IdleI2C(); // read the data unsigned char data = MasterReadI2C(); IdleI2C(); StopI2C(); return data; }
unsigned char readSRF02(char addr, char reg) { StartI2C(); while (I2CCONbits.SEN); // send the address MasterWriteI2C(addr); IdleI2C(); // send the register MasterWriteI2C(reg); IdleI2C(); StopI2C(); IdleI2C(); StartI2C(); while (I2CCONbits.SEN); // send the address again with read bit MasterWriteI2C(addr + 1); IdleI2C(); // read the data unsigned char data = MasterReadI2C(); StopI2C(); return data; }
int getRelayStates() { StartI2C(); IdleI2C(); // send the address MasterWriteI2C(writeAddr); IdleI2C(); // send the register MasterWriteI2C(RLY08_REGISTER_RELAY_STATES); IdleI2C(); StartI2C(); // send the address again with read bit MasterWriteI2C(readAddr); IdleI2C(); // send the register MasterWriteI2C(RLY08_REGISTER_RELAY_STATES); // read the data - and send an ACK int data = MasterReadI2C(); StopI2C(); return(data); }
static int i2c_read(struct i2c_platform_data *adap, unsigned char *buf, unsigned int len) { int i; u32 data; pr_debug("i2c_read\n"); i = 0; while (i < len) { data = MasterReadI2C(adap); buf[i++] = data; if (i < len) AckI2C(adap); else NotAckI2C(adap); } StopI2C(adap); IdleI2C(adap); return 0; }
char getSD21BatteryLevel (void) { unsigned char result; IdleI2C(); StartI2C(); /* Wait till Start sequence is completed */ while(I2CCONbits.SEN); MasterWriteI2C(SD21_ADDRESS_WRITE); IdleI2C(); MasterWriteI2C(REGISTER_VOLTAGE); IdleI2C(); StopI2C(); IdleI2C(); StartI2C(); /* Wait till Start sequence is completed */ while(I2CCONbits.SEN) MasterWriteI2C(SD21_ADDRESS_READ); IdleI2C(); result = MasterReadI2C();// * BATTERY_MULTIPLY_FACTOR; IdleI2C(); return result; }
unsigned int getSD21SoftwareRevision(void) { unsigned int version; IdleI2C(); StartI2C(); /* Wait till Start sequence is completed */ while(I2CCONbits.SEN); MasterWriteI2C(SD21_ADDRESS_WRITE); IdleI2C(); MasterWriteI2C(REGISTER_SOFTWARE_REVISION); IdleI2C(); StopI2C(); IdleI2C(); StartI2C(); /* Wait till Start sequence is completed */ while(I2CCONbits.SEN) //adddresse I2C de la carte MasterWriteI2C(SD21_ADDRESS_READ); IdleI2C(); version = MasterReadI2C(); IdleI2C(); StopI2C(); return (version); }
byte I2CReadByte ( byte Device, byte Address ) { byte Data = 0; // Ensure I2C module is idle IdleI2C(); // Transmit a Start condition StartI2C(); // Wait till Start sequence is completed while(I2CCONbits.SEN ); // Write Slave address and set master for transmission (R/W bit should be 0) MasterWriteI2C(Device); // Wait till address is transmitted while(I2CSTATbits.TBF); // Test for ACK condition received while(I2CSTATbits.ACKSTAT); // Ensure I2C module is idle //IdleI2C(); // Write word address for serial EEPROM MasterWriteI2C(Address); // Wait till address is transmitted while(I2CSTATbits.TBF); // Test for ACK condition received while(I2CSTATbits.ACKSTAT); // Ensure I2C module is idle //IdleI2C(); // Generate the I2C bus restart condition RestartI2C(); // Wait until re-start condition is over while (I2CCONbits.RSEN); // WWrite Slave address and set master for reception (R/W bit should be 1) MasterWriteI2C( Device+1 ); // Wait till address is transmitted while(I2CSTATbits.TBF); // Ensure I2C module is idle //IdleI2C(); // Test for ACK condition received while(I2CSTATbits.ACKSTAT); // Ensure I2C module is idle //IdleI2C(); // Read the data byte Data = MasterReadI2C(); // Ensure I2C module is idle //IdleI2C(); // send NACK condition back to the I2C slave indicating master received the data byte NotAckI2C(); // wait until NACK sequence is over while (I2CCONbits.ACKEN); // Ensure I2C module is idle //IdleI2C(); // send STOP condition StopI2C(); // Wait till Stop sequence is completed while(I2CCONbits.PEN); // Ensure I2C module is idle IdleI2C(); return ( Data ); // return with data }