0

Grand Centeral How to use Port Registers?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Grand Centeral How to use Port Registers?

by DropBear on Wed Jun 12, 2019 1:18 pm

I'm missing soemthing here.

I'm using the Arduino IDE with a Grand Central and trying to use Port Registers.
I have the SAMD and Adafruit SAMD board libraries loaded and have been able to do a few simple blink tests with individual pins.

I can see PORTA, PORTB, PORTC, PORTD, and PinDescription being defined in ibrary file variant.cpp located in ~/Library/Arduino15/packages/adafruit/hardware/samd/1.5.0/variants/grand_central_m4.

Modifying the simple blink test I have:
Code: Select all | TOGGLE FULL SIZE
void setup() {
  // Set all PORTC as output
  DDRC = 0xFF;
}

void loop() {

  PORTC = 0xFF;  // Set all digital PORTC pins on
  delay(1000);

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

But I'm getting the error:
Code: Select all | TOGGLE FULL SIZE
 port101.ino: In function 'void setup()':
port101:3:3: error: 'DDRC' was not declared in this scope
   DDRC = 0xFF;
   ^
port101.ino: In function 'void loop()':
port101:8:9: error: lvalue required as left operand of assignment
   PORTC = 0xFF;  // Set all digital PORTC pins on
         ^
port101:11:9: error: lvalue required as left operand of assignment
   PORTC = 0x00;  // Set all digital PORTC pins off
         ^
exit status 1
'DDRC' was not declared in this scope


Should I be including another file or do I need to define the registers myself?
I'm not sure how variant.cpp comes into play with the Arduino IDE.
DropBear
 
Posts: 2
Joined: Thu Dec 27, 2012 2:04 am

Re: Grand Centeral How to use Port Registers?

by adafruit_support_carter on Wed Jun 12, 2019 2:26 pm

The SAMD on the Grand Central is an ARM based processor, not AVR. You're trying to do low level AVR stuff.

adafruit_support_carter
 
Posts: 11467
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Centeral How to use Port Registers?

by DropBear on Wed Jun 12, 2019 3:25 pm

Is there a way to simply set/read a group of digital pins without a loop then?
I would hope the advertised "Parallel Capture Peripheral" with 14 Digital Pins aren't being polled individually?

The grouping of PORTA through PORTD on the schematic and in the variant.cpp seems to hint at it still.

Did find this post that also shows using PORTA with a different syntax:
https://forums.adafruit.com/viewtopic.php?f=63&t=148693&p=739206&hilit=PORTA#p739206
DropBear
 
Posts: 2
Joined: Thu Dec 27, 2012 2:04 am

Re: Grand Centeral How to use Port Registers?

by adafruit_support_carter on Wed Jun 12, 2019 4:12 pm

You may be able to, but you would need to consult the datasheet for the SAMD chip and probably the API documentation for the support library from Atmel.

adafruit_support_carter
 
Posts: 11467
Joined: Tue Nov 29, 2016 2:45 pm

Re: Grand Centeral How to use Port Registers?

by westfw on Fri Jun 14, 2019 11:18 pm

There’s an example here: viewtopic.php?f=57&t=133497#p668379
The samd chips are much different than the avrs.
westfw
 
Posts: 1525
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.