C standard port manipulation not working?

This works. Prints "DATA_RDY" when I pull AO high.

#include <Arduino.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define VBI_DATA_RDY   A0

void setup() 
{
    Serial.begin(115200,SERIAL_8N1);   
    pinMode(VBI_DATA_RDY,INPUT);
    DDRC= B01010000;
    DDRD= B00000110;
}


void loop() 
{
    while (1)  { 
  
      if (digitalRead(VBI_DATA_RDY))  {
          Serial.println("DATA_RDY");
      }
    }
}

This does not? I see nothing wrong here and it compiles with no errors.

// Include Files
#include <Arduino.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define VBI_DATA_RDY   PINC & 0x20

void setup() 
{
    Serial.begin(115200,SERIAL_8N1);   
    DDRC= B01010000;
    DDRD= B00000110;
}

void loop() 
{

    while (1)  { 
  
      if (VBI_DATA_RDY)  {
          Serial.println("DATA_RDY");
      }
    }
}

I don't want to use digitalRead(). Too slow.

Which Arduino?

UNO R3 for R&D but ultimately will be a raw MEGA328.

  • How does 0x20 equal to A0 ?

A0 is the Arduino pin name and that's what Arduino uses.

0x20 is bit #5 of a byte. Powers of 2.
PINC is port C input.

     HEX   DEC

bit0= 0x01 - 1
bit1= 0x02 - 2
bit2= 0x04 - 4
bit3= 0x08 - 8
bit4= 0x10 - 16
bit5= 0x20 - 32
bit6= 0x40 - 64
bit7= 0x80 - 128

A0 is Port C bit 0

  • Is it your intention to access A0 here ?

Oooo, my bad. I have an Excell spread sheet that follows all connections in this project. Port C was labeled backwards!

Thanks.