uint16_t exadc_read(uint8_t chan)
{
	i2c_repStart(MCP3426_I2C_WRITE_ADDR);
	// start a conversion
	// 1x PGA gain
	// 15 SPS, 16 bit
	// one-shot mode
	i2c_write(0b10001000 | ((chan & 0x03) << 5));
	i2c_stop();

	_delay_ms(70); // 15 SPS means 0.0666 seconds between samples

	i2c_repStart(MCP3426_I2C_READ_ADDR);
	uint16_t r = i2c_readAck() << 8;
	r |= i2c_readNak();

	return r;
}
Exemple #2
0
// le do endereco de 8 bits, com endereco de 8 bytes (2k bit max)
unsigned char I2C_EEIN (unsigned char address)
{
    unsigned char data;

    i2c_start();
    i2c_write(0xA0);
    i2c_write(address);
    i2c_repStart();
    i2c_write(0xA1);
    data=i2c_read(0);
    i2c_stop();
    return(data);

}