Error using bitand - Double inputs must have integer values in the integer range when mixed with integer inputs.

I'm having an issue regarding the bitand() function. I'm getting an error when I'm running the code. below is just a section of the code I'm running.
properties
SLEEP = hex2dec('10');
function
mode1 = r.i2c.readRegister(r.MODE1); %this is being read as a value of 1
mode1 = bitand(mode1, bitcmp(r.SLEEP, 'int8')); %here is where the error is occurring.
this is what pops up.
Error using bitand
Double inputs must have integer values in the integer range when mixed with integer inputs.
Error in PWM (line 50)
mode1 = bitand(mode1, bitcmp(r.SLEEP, 'int8'));
Error in MotorHat (line 22)
motor_obj.pwm = PWM(motor_obj.rpi, addr);
now if I run just bitcmp(r.SLEEP, 'int8') on its own the value is -17. I have to run it with the assumed type 'int8', because it comes back as a double value 1.8447e+19 if I don't.
anyone have any ideas as to what the issue is and how I can go about fixing it?
If i do the following
bitand(1, -17, 'int8')
i get the answer of 1. Which would be the answer I'm looking for. but for obvious reasons, I can't just insert values, I need to be able to use the variables.

4 Comments

After you read from the register, what shows up if you calculate
model - 1.0
I predict that the answer will not be exactly 0
actually when I do
mode1 - 1
ans =
uint8
0
were you thinking that it was a double , but it just wasn't giving me a the full representation?
so after you asked that question. I went in and I added
int8(mode1)
mode1 = bitand(int8(mode1), bitcmp(r.SLEEP, 'int8'));
and I'm through with no more errors. Hopefully matlab was just confused rather than the register actually being read as a double, as I don't think thats possible.
Is it possible that some of the values are >= 128 ? That would cause confusion between uint8 and int8 .

Sign in to comment.

Answers (0)

Asked:

on 13 Apr 2017

Commented:

on 14 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!