Skip to content

Commit 7edbc4b

Browse files
committed
switched to using default i2c pins
1 parent 1d0786e commit 7edbc4b

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

i2c/ina228_i2c/ina228_i2c.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
#include "hardware/i2c.h"
44
#include <math.h>
55

6-
// GPIOs, see circuit diagram
7-
#define I2C_SDA 8
8-
#define I2C_SCL 9
6+
// LED GPIOs
97
#define EXT_LED_GPIO 2
108

11-
// Shunt resistor values in ohms
9+
// INA228 integrated shunt resistance
1210
#define R_SHUNT 0.015
1311

1412
// Max expected current through shunt resistor
@@ -49,16 +47,15 @@ static void ina228_init() {
4947
i2c_write_blocking(i2c_default, I2C_ADDR, shunt_buf, 3, false);
5048

5149
// Write to ADC config register (need to enable continuous mode to access accumilation variables energy and charge)
52-
// To enable contintinuous vbus, vshunt and temp, write 0x0F to bits 15-12
53-
uint8_t adc_msb = 0xF1;
54-
uint8_t adc_lsb = 0x11;
50+
uint8_t adc_msb = 0xF0;
51+
uint8_t adc_lsb = 0x00;
5552
uint8_t adc_buf[3] = {ADC_CONFIG_REG, adc_msb, adc_lsb};
5653
i2c_write_blocking(i2c_default, I2C_ADDR, adc_buf, 3, false);
5754
}
5855

5956
static void ina228_read(float *vshunt, float *vbus, float *dietemp, float *current, float *power, float *energy, float *charge) {
6057
// Buffers for writing register measurments to
61-
// Some registers are 2 byte, some are 3 byte, the accumilation registers are 5 byte
58+
// Some registers are 2 bytes, some are 3 bytes, the accumilation registers are 5 bytes
6259
uint8_t buffer_2[2];
6360
uint8_t buffer_3[3];
6461
uint8_t buffer_5[5];
@@ -106,10 +103,10 @@ int main()
106103
i2c_init(i2c_default, 400*1000);
107104

108105
// GPIO initialisiation
109-
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
110-
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
111-
gpio_pull_up(I2C_SDA);
112-
gpio_pull_up(I2C_SCL);
106+
gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
107+
gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
108+
gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
109+
gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
113110

114111
// Initialise ina228
115112
ina228_init();

0 commit comments

Comments
 (0)