Hi all,
(System: Mega2560R3)
I need to perform fast write on-off actions to ports (2µs). digitalWrite() is too slow for this as it perfoms several look-ups and calls. So i write to the port pointers directly via sending the byte mask. For example:
PORTA = PORTA | B10000000; //Turns Pin29 on leaving all other pins as they are
delayMicroseconds(2);
PORTA = PORTA & (~B10000000); //Turns Pin29 off leaving all other pins as they are
That works fine and fast enough.
The problem: At some point before the fast read and write actions start, I need to allocate the right PORT because I use many pins which are distributed between PORTA, PORTB, PORTC, PORTD, PORTE.
This sound trivial but appreas to be beyond my intellectual horizon:
byte currentPort = PORTA;
currentPort = currentPort | B10000000; //Nothing happens. This makes sense because it just assings the byte currently in PORTA to a new vaiable. So lets try with pointers:
volatile uint8_t **currentPort ;
*currentPort = &PORTA;
**currentPort = **currentPort | B10000000; //This also does nothing. Why??
Can anyone tell me whats wrong in my thinking?