SAMD51 set port gpio pins as a group?

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

 

With a SAMD51 is it possible to set a group of digital GPIO pins simultaneously vs. each pin in a loop?

 

On a AVR it seems you can do something like this for GPIO pins in a PORT group:

void setup() {
  DDRA = 0xFF;    // Set all PORTA pins as output
}

void loop() {
  PORTA = 0xFF;  // Set all PORTA pins on
  delay(1000);

  PORTA = 0x00;  // Set all PORTA pins off
  delay(1000);
}

 

Is there a way to accomplish this with the Arduino IDE and SAMD51?  

 

Looking at the libraries the best I could find are individual pin definitions (which includes the PORT they are assigned to) for "PinDescription" and "g_APinDescription".

Example for PORTA:

{PORTA,2,PIO_ANALOG,PIN_ATTR_ANALOG,ADC_Channel0,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_2},
{PORTA,2,PIO_ANALOG,PIN_ATTR_ANALOG,DAC_Channel0,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_2},//DAC/VOUT[0]
{PORTA,3,PIO_ANALOG,PIN_ATTR_ANALOG,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_3},//DAC/VREFP
{PORTA,4,PIO_ANALOG,(PIN_ATTR_ANALOG|PIN_ATTR_PWM_E),ADC_Channel4,TC0_CH0,TC0_CH0,EXTERNAL_INT_4},
{PORTA,5,PIO_ANALOG,PIN_ATTR_ANALOG,ADC_Channel5,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_5},
{PORTA,5,PIO_ANALOG,PIN_ATTR_ANALOG,DAC_Channel1,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_5},//DAC/VOUT[1]
{PORTA,6,PIO_ANALOG,(PIN_ATTR_ANALOG|PIN_ATTR_PWM_E),ADC_Channel6,TC1_CH0,NOT_ON_TIMER,EXTERNAL_INT_6},
{PORTA,7,PIO_ANALOG,(PIN_ATTR_ANALOG|PIN_ATTR_PWM_E),ADC_Channel7,TC1_CH1,NOT_ON_TIMER,EXTERNAL_INT_7},
{PORTA,8,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_NMI},
{PORTA,9,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_9},
{PORTA,10,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_10},
{PORTA,11,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_11},
{PORTA,12,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC2_CH0,TC2_CH0,EXTERNAL_INT_12},//DEN1
{PORTA,13,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC2_CH1,TC2_CH1,EXTERNAL_INT_13},//DEN2
{PORTA,14,PIO_DIGITAL,PIN_ATTR_PWM_F,No_ADC_Channel,TCC2_CH0,NOT_ON_TIMER,EXTERNAL_INT_14},//CLK
{PORTA,15,PIO_DIGITAL,PIN_ATTR_PWM_F,No_ADC_Channel,TCC2_CH1,NOT_ON_TIMER,EXTERNAL_INT_15},
{PORTA,16,PIO_DIGITAL,PIN_ATTR_DIGITAL,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_0},
{PORTA,17,PIO_DIGITAL,PIN_ATTR_DIGITAL,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_1},
{PORTA,18,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC3_CH0,TC3_CH0,EXTERNAL_INT_2},
{PORTA,19,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC3_CH1,TC3_CH1,EXTERNAL_INT_3},
{PORTA,20,PIO_DIGITAL,PIN_ATTR_DIGITAL,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_4},
{PORTA,21,PIO_DIGITAL,PIN_ATTR_DIGITAL,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_5},
{PORTA,22,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC4_CH0,TC4_CH0,EXTERNAL_INT_6},
{PORTA,23,PIO_DIGITAL,PIN_ATTR_PWM_E,No_ADC_Channel,TC4_CH1,TC4_CH1,EXTERNAL_INT_7},
{PORTA,24,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_8},//USB/DM
{PORTA,25,PIO_COM,PIN_ATTR_NONE,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_9},//USB/DP
{PORTA,27,PIO_COM,PIN_ATTR_DIGITAL,No_ADC_Channel,NOT_ON_PWM,NOT_ON_TIMER,EXTERNAL_INT_NONE},//USBHostenable
Last Edited: Wed. Jun 19, 2019 - 10:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes. The equivalent of the AVR's OVR register is

 

PORTA.OUT.reg = 0x1

 

And the equivalent of the AVR's DDR register is

 

PORTA.DIR.reg = 0x1

 

The above would configure PA01 to an output with high voltage. You can set multiple pins by setting multiple bits in the word, e.g. to set PA0 through PA3 to a high output:

 

PORTA.DIR.reg = 0xF;

PORTA.OUT.reg = 0xF;

 

You will need to include "samd51.h" and "port.h" to get the right defines. The exact labels might change a bit with different versions of ASF. I've looked at 3.45 for this post.

Josh @ CIHOLAS Inc - We fill the gaps from chips to apps

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

Ah! Thank you!