Czy ktoś posiada sprawdzony program w bascom do obsługi INA219?
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam
$regfile = "M16def.dat"
Const Ina226_adr_w = &H80 ' Adres zapisu INA226
Const Ina226_adr_r = &H81 ' Adres odczytu INA226
Dim Ina226_reg As Byte , W_high As Byte , W_low As Byte
Dim U_high As Byte , U_low As Byte , I_high As Byte , I_low As Byte
Dim 24vdc As Single , I As Single
'------------ konfiguracja I2C
$lib "i2c_twi.lbx"
Config Scl = Portc.0
Config Sda = Portc.1
Config Twi = 100000
I2cinit
'------------- inicjalizacja INA226
W_high = &B01000101 ' 16 pomiarów do uśredniania, 1,1 ms czas pomiaru prądu i napięcia
W_low = &B00100111 ' ciągły pomiar napięcia i prądu
Ina226_reg = &H00
Gosub Ina226_reg_write
W_high = &B00001000 ' zapisuje rejestr kalibracyjny
W_low = &B00000000 ' żeby można było czytać od razu prąd w amperach
Ina226_reg = &H05
Gosub Ina226_reg_write
'------------- odczyt INA226
Gosub Ina226_reg_read_u
24vdc = U_high
Shift 24vdc , Left , 8
24vdc = 24vdc + U_low
24vdc = 24vdc * 0.00125 ' voltage_LSB = 0,00125 V
Gosub Ina226_reg_read_i
I = I_high
Shift I , Left , 8
I = I + I_low
I = I * 0.00005 ' current_LSB = 0.00005 A
'------------- procedury
Ina226_reg_read_u:
I2cstart
I2cwbyte Ina226_adr_w
I2cwbyte &H02
I2cstart
I2cwbyte Ina226_adr_r
I2crbyte U_high , Ack
I2crbyte U_low , Nack
I2cstop
Return
Ina226_reg_read_i:
I2cstart
I2cwbyte Ina226_adr_w
I2cwbyte &H04
I2cstart
I2cwbyte Ina226_adr_r
I2crbyte I_high , Ack
I2crbyte I_low , Nack
I2cstop
Return
Ina226_reg_write:
I2cstart
I2cwbyte Ina226_adr_w
I2cwbyte Ina226_reg
I2cwbyte W_high
I2cwbyte W_low
I2cstop
Return