SAM4n trouble reading gpio -- solved

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to read a few gpio inputs pa0-pa3.  I have various logic level voltages asserted to the different pins so I can see a pattern when it starts working.  But for the life of me, I can not see the PIO_PDSR register reflect the value of the input pins.

Here is my code.  Most of these are the power up defaults, I know.

Am I missing something in the initialization of the pins?  Or is there something else I still need to do?  The PIO_PDSR is always reading 0x00000000.


#define SEL0	0
#define SEL1	1
#define SEL2	2
#define SEL3	3

void initAddress( void )
{
    // get a pointer to the pio peripheral
    Pio * pio = PIOA;

    // enable pio to be written (disable write protect)
    pio->PIO_WPMR = 0x50494f00;

    // set them to gpio
    pio->PIO_PER = ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 );

    // disable the output write for these four pins
    pio->PIO_OWDR = ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 );

    // set the pull ups
    pio->PIO_PUER = ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 ) | ( 1 << SEL0 );
}

uint8_t readAddress( void )
{
    uint32_t data;

    // get a pointer to the pio peripheral
    Pio * pio = PIOA;

    //read all the pA gpio
    data = pio->PIO_PDSR;
}

 

Thanks for your help!

 

Aaron

Last Edited: Wed. Aug 16, 2017 - 06:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I solved it, I needed to turn on the PMC clock to PIOA

 

// get a pointer to the PMC
Pmc * pmc = PMC;
	
// enable the clock to the pioa peripheral
pmc->PMC_PCER0 |= ( 1 << 11 );

 

Now all the inputs are reflected in the register as expected.