I2C write macro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

I2C write macro

Post by Jan Lichtenbelt »

Can someone check if my I2C write macro is correct?
Current_sensor_INA219_V1.fcfx
(30.78 KiB) Downloaded 357 times
Thanks a lot

Jan Lichtenbelt

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: I2C write macro

Post 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

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: I2C write macro

Post 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
Current_sensor_INA219_V6.fcfx
(36.07 KiB) Downloaded 316 times

Post Reply