Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: port manipulation - What am I doing wrong?

  1. #1
    Junior Member
    Join Date
    Sep 2016
    Posts
    3

    port manipulation - What am I doing wrong?

    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;
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	dacTest.png 
Views:	32 
Size:	3.8 KB 
ID:	12075  

  2. #2

  3. #3
    Junior Member
    Join Date
    Sep 2016
    Posts
    3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •