Go Down

Topic: Convert Arduino pins to AVR PORTs (Read 5270 times) previous topic - next topic


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: [Select]
uint8_t sPort = digitalPinToPort(13);
bitSet(sPort, 5);

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



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.

Go Up