I am having a spot of bother with converting i2c register manipulations from Arduino to Squirrel. I want to do this:
`c = readByte(i2cAddr, ACCEL_CONFIG); // writeRegister(ACCEL_CONFIG, c & ~0xE0); // Clear self-test bits [7:5] i2c.write(i2cAddr, ACCEL_CONFIG, c & ~0x18); // Clear AFS bits [4:3] i2c.write(i2cAddr, ACCEL_CONFIG, c | Ascale << 3); // Set full scale range for the accelerometer `
That is, read a register, clear the bits I am about to set and only them, then write those bits to their proper value. I am getting hung up with the difference between strings and integers in squirrel and it’s either complaining during run or not changing the register as I want.
I tried something like this:
`// Set accelerometer full-scale range configuration local c = i2c.read(i2cAddr, ACCEL_CONFIG, 1); // i2c.write(i2cAddr, ACCEL_CONFIG + (c & ~"\\x18")); // Clear AFS bits [4:3] i2c.write(i2cAddr, ACCEL_CONFIG + "(c | Ascale << 3)"); // Set full scale range for the accelerometer `
which compiles and runs, but doesn’t show any change to the register.
Please help if you can. Thanks.