input pins using ASF? -- solved

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

I'm on a sam4n8 and simply trying to read the input pins.  I've tried using direct port access and failed, now trying using ASF and also failing.  ARGH!

I can configure a pin to be an output and toggle it, but I can not get ANY inputs to work.

 

Here is a sample of my code using ASF.  The LED portion works fine.  But the input which should be 0b1001 is not, it's all ways 0.  Even looking at the registers, PIO_PDSR is always 0x00000000, but I have 3.3V on pins (36) pa0 and (31) pa3.

Any ideas?

#define LED          IOPORT_CREATE_PIN(PIOA, 16)	//PIN of connection LED pa16
ioport_set_pin_dir(LED, IOPORT_DIR_OUTPUT);			//PIN as output
ioport_set_pin_level(LED, IOPORT_PIN_LEVEL_LOW);	//Set pin to LOW level
ioport_set_pin_level(LED, IOPORT_PIN_LEVEL_HIGH);   //Set pin to HIGH level
ioport_set_pin_level(LED, IOPORT_PIN_LEVEL_LOW);	//Set pin to LOW level
ioport_set_pin_level(LED, IOPORT_PIN_LEVEL_HIGH);   //Set pin to HIGH level

#define SEL0	IOPORT_CREATE_PIN( PIOA, 0)
#define SEL1	IOPORT_CREATE_PIN( PIOA, 1)
#define SEL2	IOPORT_CREATE_PIN( PIOA, 2)
#define SEL3	IOPORT_CREATE_PIN( PIOA, 3)

ioport_enable_pin( SEL0 );
ioport_enable_pin( SEL1 );
ioport_enable_pin( SEL2 );
ioport_enable_pin( SEL3 );

ioport_set_pin_dir(SEL0, IOPORT_DIR_INPUT);
ioport_set_pin_dir(SEL1, IOPORT_DIR_INPUT);
ioport_set_pin_dir(SEL2, IOPORT_DIR_INPUT);
ioport_set_pin_dir(SEL3, IOPORT_DIR_INPUT);	

bool level;
level = ioport_get_pin_level( SEL0 );	// false, should be true
level = ioport_get_pin_level( SEL1 );	// false
level = ioport_get_pin_level( SEL2 );	// false
level = ioport_get_pin_level( SEL3 );	// false, should be true

 

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

I solved this, I needed to call ioport_init(); Which I finally found mention of on

http://asf.atmel.com/docs/latest/sam4n/html/ioport_quickstart.html

 

This also led me to the solution for my direct port access code, since all the ioport_init() does is activate the clock for the peripheral.