GPIO in SAMD21

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

Hi

I have started configuring GPIO pins.
Please find code below.
 


#define Pincfg                  	0x06
#define PA13			        	(1 << 13)
#define PORTA			        	PORT->Group[0]
#define RX			            	PA13
#define Read_IO_PA13()              ((PORTA.IN.reg)>>13)

    int main()
    {
        unsighed char readdata;

        PORTA.DIRCLR.reg = RX; //set direction as input

        PORTA.PINCFG[13].reg |= Pincfg; //enable input buffer and internal pull

        readdata = Read_IO_PA13();
        return 0;
    }

I am unable to read pin PA13.
Please help me to resove this.
 

Compiler: Mplab X
Using simulator in above mentioned compiler
Microcontroller: samd21g17d

Last Edited: Wed. Apr 22, 2020 - 10:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You must enable clocks first.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its random occurrence, sometimes I am able to read value on pin, sometimes I can't read it.

Please elaborate on how to configure clock specifically for GPIO configurations as I couldn't find it in datasheet.

Is it like when we configure timer, we select Generic clock generator as input to TCx?
 

Thanks!

Last Edited: Wed. Apr 22, 2020 - 01:11 PM