I'm currently working on a project where I read a 32 bit sequence. The digitalPin is always HIGH when no sequence is received and starts oscilating with about 1kHz when the sequence starts (RC5).
I am setting and clearing bits of an uint32_t depending on which signal is on the digitalPin. It seems to work very well with every bit except of the MSB.
Here a short code snippet to show what I mean:
const short irPin = 8;
const short msgDelay = 250;
uint32_t data = 0xFFFFFFFF;
long msgArrived = 0;
void setup(){
Serial.begin(115200);
pinMode(irPin, INPUT);
}
void loop(){
long now = millis();
if( (!(PINB & 1)) && ((now - msgArrived)> msgDelay)){
msgArrived = millis();
bitClear(data, 31);
Serial.println(data, BIN);
}
}
This gives me an output of
11111111111111111111111111111111
I have already tried
bitClear(data, 32); -> 11111111111111111111111111111111
bitClear(data, 30); -> 10111111111111111111111111111111
So every output is right, but not the when I try to clear the msb.
Has anyone experienced a similar behaviour?
data &= ~(0x1 << 31)
?