Go Down

Topic: Issue with digitalWrite (Read 962 times) previous topic - next topic

jopiek

I'm creating my own sort of one wire protocol (to drive a attiny10):

when I drive the line low for a moment the other side starts reading pulses.

So far so good. But I detect that:

if I do a digitalWrite(line, HIGH); (e.g. on D12 or D13), the other side starts to respond.

it should only respond to a digitalWrite(line, LOW);

To confirm this issue I also tried it with:

Code: [Select]

PORTB &= ~1<<PINB5;
 delay(1000);
 PORTB |= 1<<PINB5;
 delay(1000);


That gives exactly the expected behavior.

It seems that digitalWrite(x, HIGH) does more than PORTB &= (1 << PINB4);

That is very interesting isn't it?!

Coding Badly


I assume from your post that you are trying to claim digitalWrite is buggy.  Before making that claim, you may want to correct a mistake in your snippet and rerun your test.

Code: [Select]
  PORTB &= ~1<<PINB5;

Bitwise-not has a higher precedence than shift-left.  I'll let you work out what that line of code really does.

Graynomad

What CB said, check out operator precedence, remember that these core functions have been around for a LONG time, the chance of an undocumented bug is essentially 2/5ths of 5/8ths of bugger all.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Riva


What CB said, check out operator precedence, remember that these core functions have been around for a LONG time, the chance of an undocumented bug is essentially 2/5ths of 5/8ths of bugger all.

Surly you mean just two chances. Fat & Slim :D

jopiek

#4
Jul 03, 2012, 04:50 pm Last Edit: Jul 03, 2012, 04:56 pm by jopiek Reason: 1
Of course it does, that was my mistake, but that must have been the rush this morning before going to work. I corrected it the way I normally do it, so with parenthesis before the 1 and a closing one before the semicolon.

Didn't change the effect (actually I programmed it correctly but posted it here incorrectly). I will use my scope to it to see the effects, but not before tonight. No matter what, I detect a high/low switch when I perform a drigitalWrite(x, HIGH). Not that it matters to me but I thought it would be interesting to you all. I use a recent rev. UNO b.t.w. it could be hardware related of course.


Code: [Select]

PORTB &= ~(1<<PINB5);
  delay(1000);
  PORTB |= (1<<PINB5);
  delay(1000);



No offense, but I consider just exploring it myself and then just share it with my students ;)

Go Up