Level1_SensorNode/sensor_all/i2c_basics.cpp
//================================================================================================//
// read_i2c() --- Read bytes from i2c device                                                      //
// Argument : uint8_t addr  - The address of the device to communicate with                       //
//            uint8_t reg   - The register value to send to the i2c device                        //
//            uint8_t n     - The number of bytes to receive from the i2c device                  //
//            uint8_t *data - The data array pointer to write received data                       //
// Returtn  : None                                                                                //
//================================================================================================//
Read bytes from i2c device
Argument : uint8_t addr  - The address of the device to communicate with
uint8_t reg   - The register value to send to the i2c device
uint8_t n     - The number of bytes to receive from the i2c device
uint8_t *data - The data array pointer to write received data
Returtn  : None
Read bytes from i2c device Argument : uint8_t addr - The address of the device to communicate with uint8_t reg - The register value to send to the i2c device uint8_t n - The number of bytes to receive from the i2c device uint8_t * data - The data array pointer to write received data Returtn : None
void read_i2c(uint8_t addr, uint8_t reg, uint8_t n, uint8_t* data) {
  uint8_t i = 0;
  Wire.beginTransmission(addr); 
  Wire.write(reg);              
  Wire.endTransmission();       
  Wire.requestFrom(addr, n);    
  while (Wire.available()) data[i++] = Wire.read();
}
void read_i2c ( uint8_t addr , uint8_t reg , uint8_t n , uint8_t * data ) { uint8_t i = 0 ; Wire . beginTransmission ( addr ) ; Wire . write ( reg ) ; Wire . endTransmission ( ) ; Wire . requestFrom ( addr , n ) ; while ( Wire . available ( ) ) data [ i ++ ] = Wire . read ( ) ; }
read_i2c() --- Read bytes from i2c device
Argument : uint8_t addr  - The address of the device to communicate with
uint8_t reg   - The register value to send to the i2c device
uint8_t n     - The number of bytes to receive from the i2c device
uint8_t *data - The data array pointer to write received data
Returtn  : None
read_i2c () --- Read bytes from i2c device Argument : uint8_t addr - The address of the device to communicate with uint8_t reg - The register value to send to the i2c device uint8_t n - The number of bytes to receive from the i2c device uint8_t * data - The data array pointer to write received data Returtn : None
// Set address of the device // Write the register // End transmission // Request the i2c device to send n bytes