Pages: [1]   Go Down
Author Topic: Issue with digitalWrite  (Read 762 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
  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.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8436
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Norfolk UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-grin
Logged

Handle every stressful situation like a dog. If you can't eat it or hump it. Piss on it and walk away.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 smiley-wink
« Last Edit: July 03, 2012, 09:56:51 am by jopiek » Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you remember to set the pin to OUTPUT?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, I won't go further with this... I have used Atmel uC for some years now, I have programming experience as a software engineer since 1997, I teach computer science both at high school and university, etc. I even wrote a complete educational Arduino program for high schools all around my country.

So I screwed up my first post because of being in a hurry (I should have done better, I agree). I know there are a lot of novice users here, but sorry this topic was a mistake it will lead to nothing. (of course I set the DDR on port B by using pinMode in Arduino). I am a bad reader myself, but a lot of experienced people here don't seem to read my issue and just comment by doing lucky guesses...

My mistake. I will just enjoy the fun of Arduino with myself and my always positive, helping and understanding students smiley
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(of course I set the DDR on port B by using pinMode in Arduino).
Well you didn't really post anything someone else could test with.  So you left the door wide open for assumptions.  You gave a vague issue and expect precise answers. 

The behavior you are describing with digitalWrite() doesn't make sense.  The behavior with (the correct) direct port manipulation doesn't make sense.  In all the time I watched digital outputs on my scope, I have never captured a spurious transition like you suggest.  So something else is going on.  For example, is there another function those pins have that are interfering with their operation?  What is the hardware on the other side?  etc.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24317
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but a lot of experienced people here don't seem to read my issue and just comment by doing lucky guesses...
In the absence of full code what are they supposed to do?

Quote
I won't go further with this.
Do you want me to delete/move/lock the thread?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: