Page 1 of 1
I2C write macro
Posted: Sat Jun 24, 2017 11:43 am
by Jan Lichtenbelt
Can someone check if my I2C write macro is correct?
Thanks a lot
Jan Lichtenbelt
Re: I2C write macro
Posted: Sun Jun 25, 2017 5:28 pm
by mnf
Hi Jan,
Are you having a problem with it?
Note that if you used SendByteTransaction it compiles to:
Code: Select all
FCL_DEVICE_ID = FCL_DEVICE_ID << 1;
FC_CAL_I2C_Master_Start_1();
FC_CAL_I2C_Master_TxByte_1(FCL_DEVICE_ID);
FC_CAL_I2C_Master_TxByte_1(FCL_ADDRH);
FC_CAL_I2C_Master_TxByte_1(FCL_ADDRL);
FC_CAL_I2C_Master_TxByte_1(FCL_DATA);
FC_CAL_I2C_Master_Stop_1();
- you would have to use parameters addrH as Pointer_addr, addrL as Write_Calibration_Reg_H and data as Write_Calibration_Reg_L which reads somewhat confusingly.
Your code mimics this so should be ok.... Are you getting any communication with the INA219 device?
Martin
Re: I2C write macro
Posted: Sat Aug 19, 2017 2:55 pm
by Jan Lichtenbelt
It took a while, but the current sensor INA219 is working correctly now. The sensor monitors 2 voltages over a shunt and calculate the current. The same could be done by means of a microchip with 2 ADC's. But it is nice to learn to work with I2C.
Here the working program is to read the current sensor by means of a PIC16F1847. The shunt voltage and current are shown on a LCD. Three warning LED's are also available, with a little different voltage range for the charging an discharging process, based on my experiences.
I used this in a project to learn charging a Li-battery. The step-up is simple: 6V power supply -> Li-battery charger MIC79050 (very simple, just input and output up to 1 A charging)
-> the shunt resistance of 0.1 Ohm -> Li-Battery (3-4.2 Volt, 800 mAh). Parrallel to the shunt the INA219 current sensor has been placed.
Have a nice week-end
Jan Lichtenbelt