Skip to main content
Arduino

Return to Question

Commonmark migration
Source Link

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][1]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? [1]: http://www.clearwater.com.au/code/rc5

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][1]).

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? [1]: http://www.clearwater.com.au/code/rc5

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?

Tweeted twitter.com/StackArduino/status/743973521383108608
Source Link
elhe
  • 85
  • 1
  • 6

bitClear doesn't work on most significant bit

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][1]).

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? [1]: http://www.clearwater.com.au/code/rc5

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /