Trying to get a read out of the register and keep getting an error relating to:
for (int i = 0; i < 8; i++) {
// Mask each bit in the byte and store it
bits = (byte >> i) & mask;
Serial.print(i);
Serial.print(" = ");
Serial.println(bits);
}
it does not like the unsigned char to int conversion.
error: incompatible types in assignment of 'int' to 'unsigned char [8]'
bits = (byte >> i) & mask;
Whats the reason??
This is the latest code I have used for debug
#include <Wire.h>
#define PMIC_ADDRESS 0x6B
byte val;
byte BQ_REG[10] = { 0x01, 0x2, 0x03, 0x04, 0x05, 0x06,0x07,0x08, 0x09 };
byte OTG = 0x2B;
int PA18;
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
Wire.begin();
// Check battery status
analogReadResolution(12);
int sensorValue = analogRead(ADC_BATTERY);
float voltage = sensorValue * (4.208 / 4095.000);
if (voltage < 3.000) { // BATLOWV REG04[1] = 1 {
Serial.println("Battery voltage below 3.0V - Battery BOOST mode not allowed!");
return;
}
else {
Serial.print("Voltage: ");
Serial.println(voltage);
}
// Check watchdog timer status
Wire.beginTransmission(PMIC_ADDRESS);
Wire.write(BQ_REG[4]); // REG05
Wire.endTransmission();
Wire.beginTransmission(PMIC_ADDRESS);
Wire.requestFrom(PMIC_ADDRESS, 1);
Wire.endTransmission();
val = Wire.read();
Serial.print("Watchdog timer value is: ");
Serial.println(val);
if (val != 154) { // 154 DEC = 9A
Serial.println("Watchdog timer is enabled, we're going to disable it now");
Wire.beginTransmission(PMIC_ADDRESS);
Wire.write(BQ_REG[4]); // REG05
Wire.write(0x9A); // Enable Termination, match ITERM, Set Watchdog timer to 00, Safety timer on, Fast Charge 8hrs
Wire.endTransmission();
}
// Check OTG pin High and OTG register REG01[4:5] to 10
PA18 = digitalRead(PIN_USB_HOST_ENABLE);
Serial.print("PA18 is: ");
Serial.println(PA18);
Wire.beginTransmission(PMIC_ADDRESS);
Wire.write(BQ_REG[0]); // REG 01
Wire.write(OTG); // don't reset, normal watchdog, 10=OTG mode, 1011 = 3.5V min sys voltage
Wire.endTransmission();
}
void loop() { // We dump now all the registries of the BQ chip
for (int r = 0; r < 9; r++) {
Wire.beginTransmission(PMIC_ADDRESS);
Wire.write(BQ_REG[r]);
Wire.endTransmission();
Wire.beginTransmission(PMIC_ADDRESS);
Wire.requestFrom(PMIC_ADDRESS, 1);
Wire.endTransmission();
val = Wire.read();
Serial.print("Register ");
Serial.print(BQ_REG[r]);
Serial.print(" = 0x");
if (val<15)
{
Serial.print("0");
}
Serial.print(val, HEX);
Serial.print(" Bits (0-7) : ");
unsigned char byte = val;
unsigned char mask = 1;
unsigned char bits[8];
// Extract the bits
for (int i = 0; i < 8; i++) {
// Mask each bit in the byte and store it
bits[i] = (byte >> i) & mask;
Serial.print(bits[i]);
Serial.print(" ");
}
Serial.println(" ");
}
Serial.println(" ");
delay(10000);
}
Behold81:
...
Whats the reason??
// Mask each bit in the byte and store it
bits = (byte >> i) & mask;
There is a mistake in your code, should be >>
bits[i] = (byte >> i) & mask;
ballscrewbob:
TOPIC SPLIT
DO NOT HIJACK !
Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum.
Bob.
Was that aimed at me? how was this a topic split? I was identifying a bug in the code provided to assist with reading the register.
Smile6905:
There is a mistake in your code, should be >>
bits[i] = (byte >> i) & mask;
Thankyou. the newer code works. now to work out if i can find my issue.