hello, we are going to be writing an arduino C/C++ library in the same style as ladyada…
Jump to turn (63)
- 1hello, we are going to be writing an arduino C/C++ library in the same style as
- 2there are registers 0x07 through 0x0C missing
- 3please extend the list of registers to inclue 0x07 through 0x0C as well
- 4please add to that list of registers 0x11 and 0xFE and 0xFF
- 5perfect, please make the AdafruitINA2331.h header skeleton file first, and put t
- 6please make the getter for the 2-byte MANUFACTURER ID register, i do not need th
- 7please add 'AdafruitI2CDevice i2c;' to the class function and use that as the i2
- 8great - nice work. please do the same for register "DIE ID"
- 9now we can write the 'bool begin(uint8t i2caddr, theWire)' function. it will 'de
- 10sorry we should call the private variable 'i2cdev'
- 11the begin() should also check that the die and id are correct, check datasheet f
- 12use the getters we made before please!
- 13nice lets write float getShuntVoltage(uint8t channel). verify channel is between
- 14return NaN if the channel is invalid
- 15do the same for float getBusVoltage(channel), its still a signed int16t raw valu
- 16write a setter called 'void setShuntResistance(float ohms)' which will save the
- 17please also make a getter
- 18now write 'float getCurrentAmps(uint8t channel)' which will return the shunt vol
- 19ok now we will work on the configuration register. writebool reset()which writes
- 20woops baby woke up ill be back later to continue
- 21hi, baby wanted to go outside, but we're back now - lets keep coding :) :) :)
- 22next write 'bool enableChannel(uint8t channel)' which will set one of bits 12-14
- 23perfect! next up lets make the header enum for all the possible values of 'AVG2-
- 24please typedef it ina2331avgmode'
- 25please add doxygen ///< comments for each line and the enum itself, this will al
- 26please prefix each with INA2331AVG...
- 27perfect, now do the same kind of enum for " 2-0 " in the control register
- 28call the last four, '1MS' through '8MS"
- 29thanks - in the doxygen comments you can note the exact times
- 30actually call each one INA3221CONVTIME... since its used for another purpose too
- 31ok finally do the enum for MODE [3-1] in the control register
- 32you skipped 0b100, call it POWERDOWN2 and fix the last 3 enum values
- 33now its correct! lets go back and do the setter and getter for the AVG2-0 bits u
- 34in the doxygen, list all the possible args that can be passed to the setter, or
- 35ok now do VBUSCT 2-0 setters and getters for BusVoltageConvTime
- 36now duplicate for the ShuntVoltageConvTime bits
- 37finally, please write setMode and getMode for the MODE [3-1] bits
- 38now we will continue to the Critical-Alert and Warning-Alert setters and getters
- 39great, next we will do bool setPowerValidLimits(float lowVlimit, float highVlimi
- 40actually since we divide and mul by 8 we dont need the / 8's
- 41ok now we will do the complex Mask/Enable Register - start with creating #define
- 42the 'latch'
- 43sorry, i mistyped, ignore that. the 'latch' labeled bits are NOT flag bits, plea
- 44hmm nope still not right: we only need flags for bits: 9, 8, 7, 6, 5, 4, 3, 2, 1
- 45still not good, here's the table pasted: Bit Field Type Reset Description 15 Res
- 46much much better, except swap WF1 & WF3 and CF3 and CF1
- 47now that we have them correct, you can remove the MASK text and maybe make the r
- 48very good - please change the 1 to 1UL for bitshifting safety. then write uint16
- 49change CVREADY to CONVREADY and to TIMECONT in both #defines and this function,
- 50write bool setSummationChannels(bool ch1, bool ch2, bool ch3) which sets SCC1-3
- 51you can use RegisterBits to make this simpler, then you can just | the shifted b
- 52CH3 and CH1 should be swapped in the shifting statment
- 53write float getShuntVoltageSum() using Shunt-Voltage Sum Register, after reading
- 54actually, sorry this should be getCurrentSum, and divide the voltage by the shun
- 55we should probably have an array of three shunt resistances, one for each channe
- 56update getCurrentAmps to reference the shuntres array
- 57check if the voltage is NAN before dividing
- 58ok i think we're done with all of the functions, whew! please generate the heade
- 59please write the constructor, the default shunt resistances are 0.05 ohm
- 60next update setup() to check the manuf id and die id, and perform a soft reset
- 61great please now write the arduino basic test sketch which will initialize the i
- 62in the INA2331 begin function, we'll also need to enable all three channels, set
- 63add the default settings info to the doxygen too
- User
hello, we are going to be writing an arduino C/C++ library in the same style as ladyada / limor fried / adafruit for the INA3221 chip. this library will comprise a header file, called Adafruit_chipname.h and Adafruit_chipname.cpp (where chipname is the part number of the chip) and a test example . the class name will also be Adafruit_chipname.
here is the pdf datasheet that has explanations of all registers:
please read the pdf so that we can later write the #defines, enums, setters and getters to allow the library to adjust and read/write all of the settings for this chip! all the setters/getters will use Adafruit_BusIO as the library interface for I2C. each function will create a register object first, using this function prototype for Adafruit_BusIO_register:Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr, uint8_t width = 1, uint8_t byteorder = LSBFIRST, uint8_t address_width = 1);and then the setter/getter will create the object to allow access to the individual bits inside the register. Here is the function prototype for it:Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift);note that if the data we are reading/writing uses the entire register rather than a subset of the bits, we can skip the RegisterBits object and just read/write directly from Adafruit_BusIO_Register.