Pages: [1]   Go Down
Author Topic: Convert Arduino pins to AVR PORTs  (Read 1676 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 4
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am trying to write an interrupt that uses bitSet(), bitClear(), bitRead(), etc., to manipulate the ports for speed, rather than digitalRead() and digitalWrite().  Why do I need that speed?  I don't, actually.  But I want to do it because I want to learn more about the AVR, I want to get my chops up, and because it's there (tm).

But bitSet() has two arguments: The PORT, and the pin in the PORT.  However, I would like my library that includes this interrupt to take the Arduino pin as its argument; I don't want the programmer to have to figure the PORT and pin.

Can anyone explain to me why this works:
Code:
uint8_t sPort = digitalPinToPort(13);
bitSet(sPort, 5);

But this does not?
Code:
bitSet(digitalPinToPort(13), 5);
...This one says, "error: lvalue required as left operand of assignment".

Thanks.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you have a misunderstanding of what bitSet does. The argument names may be port and pin, but the function actually sets the nth bit (pin) of any byte (port).

So, the first argument is the one that you want to modify. You can't modify the output of a function (an lvalue - the left side of an equal sign - needs to be writable). The second one defines which bit to change.
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This Instructable post might be interesting for you to read:

http://www.instructables.com/id/Arduino-is-Slow-and-how-to-fix-it/step1/The-Truth-about-Pins/
Logged

Pages: [1]   Go Up
Jump to: