port manipulation - What am I doing wrong?

Status
Not open for further replies.

8thscale

New member
Here is a simple program, I just want to count on PORTD.
- Windows 1.8.2, Teeny 1.37
- the attached image shows D0..D7, 2,14,7,8,6,x,x,5, (Note: D5&6 are NOT connected)
Problems:
- bits are shuffled
- D1 & D3 aren't being driven
- those w/ keen eyes will notice the period is also wrong ...
I've tried this on a 3.2 and 3.6 with the same result.

Thank you
Dave


// --- --- ---
const uint8_t LED_PIN = 13;
// we are using all PORTD pins, direct access

elapsedMicros usec = 0;
uint8_t tblNdx;

void setup()
{
pinMode(LED_PIN, OUTPUT);

DDRD = 0xFF;
PORTD = 0x00;

tblNdx = 0;
}

void loop()
{
digitalWrite(LED_PIN, digitalRead(LED_PIN) ^ 0x01);
//
PORTD = tblNdx++;
while (usec < 500) ; // wait
usec = usec - 500;
}
 

Attachments

  • dacTest.png
    dacTest.png
    3.8 KB · Views: 98
Thanks manitou!

A few comments
- as stated GPIOD_PDOR works correctly
- I was unable to get GPIOD_PDDR to work and resorted to pinMode() as in the example
Those two changes to my code and it now behaves as expected.

Perhaps the following link could be updated ... since PORTD doesn't really work as stated.
- https://www.pjrc.com/teensy/pins.html
 
Status
Not open for further replies.
Back
Top