As an external reference, I applied a 5.0V voltage. I would like to measure voltage in the range of 0-5V with two inputs. In order to calculate internally in the microcontroller I would like to measure the external reference with the ADC, however, I measure everything else but not 5V I measure 3048mV, which is 1V more than the internal reference. But I don't know exactly what I'm doing wrong in register 0 is 0xC1 and in register 1 is 0xBA. In register 2 and 3 there is 0x00. Reading out is the same as with an analog input, I assume. I also read out the internal temperature. However, I fully understand how that can be calculated with MSB = 1, which is the other way around for me than in the data sheet. If I have 25 degrees, MSB 1 is theoretically minus for me but not according to the calculation. For the temperature, register 1 is 0xBB, register 0 has no influence and registers 2 and 3 are 0x00.
func read_REF() I2C1_Start(); I2C1_Write(0x80); //device adress I2C1_Write(0x40); //registdr 0 I2C1_Write(0xC1); //config (V(REFP) – V(REFN)) / 4 monitor (PGA bypassed) gain = 1, bypassed enabled I2C1_Stop(); pause(5); I2C1_Start(); I2C1_Write(0x80); //device adress I2C1_Write(0x44); //registdr 1 I2C1_Write(0xBA); //config temp OFF and Ref extern I2C1_Stop(); pause(5); I2C1_Start(); I2C1_Write(0x80); //device adress I2C1_Write(0x10); //read out Register I2C1_Stop(); I2C1_Start(); I2C1_Write(0x81); //device adress + read bit REFMSB = I2C1_Read(); I2C1_Ack(); REFMB = I2C1_Read(); I2C1_Ack(); REFLSB = I2C1_Read(); I2C1_Nack(); I2C1_Stop(); endfunc func read_Temp() I2C1_Start(); I2C1_Write(0x80); //device adress I2C1_Write(0x44); //registdr 1 I2C1_Write(0xBB); //config temp ON and Ref extern I2C1_Stop(); pause(5); I2C1_Start(); I2C1_Write(0x80); //device adress I2C1_Write(0x10); //read out Register I2C1_Stop(); I2C1_Start(); I2C1_Write(0x81); //device adress + read bit TempHigh = (I2C1_Read()<<10); I2C1_Ack(); TempLow = I2C1_Read(); I2C1_Nack(); I2C1_Stop(); TempHigh = TempHigh >>4; Temperatur = (TempHigh + TempLow); endfunc