Port Registers for MKR1000 and MKR1010

Does anyone know what the Port register names for the MKR series are?

I am unable to find the Port Register names (e.g: PORTD, PORTC, etc.) specific for the MKR series, since they use a different chip set than the ATmega8, ATmega168.

I need to do some direct register manipulation and require the name (and mask if possible) for the Digital Ports (PORTD in Arduino Uno).

Any help would be greatly appreciated as I have spent 24 hrs researching and trying different approaches unsuccessfully.

Thanks,

Ignacio

The MKR boards use a SAMD21 (family) chip which is a Cortex M0+ architecture. The ports and pins are entirely different than the AVR chips. You'll need to go into Board Manager and download the board package for SAMD to get the pin assignments. After that, get a copy of the datasheet and look at some of the examples. Accessing the pins is a multi step process. I believe that much of the Arduino functionality has been mapped to the new chips, but you still need to study up on the differences. If you've had some experience with the Due it will help.

@DKWatson thank you for your quick response. I already have the package for the SAMD HW and I have looked in all the .h files for both MKR1000 and MKR1010 and I cannot find the definition of the Digital ports either by group or individually. I have found definitions of all the analog, and comms pins but for some odd reasons the digital ones are not declared or I am missing something. Do you know which folder/file it might be under? The one were I saw most definitions of pins was the variants files.

There is a also a map of the pins in one of the .h files that make reference to PORTA and PORTB but I think that is just information as when I try to use those port names the compiler can't find the definition in any of the libraries included for the MKR device.

Thanks,

Ignacio

Hi

There is some discussion on port manipulation with the Zero here, and with the Due here.

Both boards use cortex-m chips. The info in both discussions may be useful

The SAMD chips use a pretty significantly different phillosophy when it comes to IO Ports.
The AVR has DDRB, PINB, and PORTB registers for control, input, and output to a set of 8pins (and similar for PORTC and PORTD.)

SAMD has 128bytes of registers for each (up to) 32bits of pins, in a nice regular array,
These registers start at an address defined in the CMSIS files (.../tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/ ) as an array named PORT. Each element of the PORT array is a PortGroup structure (which seems backwards to me. Sigh.)
So the "A" pin registers are referenced as PORT->Group[0].individualRegister

and the "B" pin registers are "A" pin registers are PORT->Group[1].individualRegister
The arduino code "helpfully" defines PORTA and PORTB as 0 and 1, which means you can say stuff like:

      PORT->Group[PORTA].OUTSET.reg = 1<<pinnumber ;

Note the lovely combination of pointers, arrays, and structure references.
(however, most of the calculations that it looks like would be required will happen at compile time, so it's not quite as bad as it seems.)

The individual register names are described in the datasheet (section 22.7 in my copy), and reflected by definitions you can find in .../tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/component/port.h
There are also names defined for every individual register in .../tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/instance/port.h, so you could have coded the above line as

REG_PORT_OUTSET0 = 1<<pinnumber ;

There are various reasons why access via the structure is preferred, though.
The SAMD doesn't have any special instructions for accessing IO bits, so bit-banging never gets as efficient as the single instructions that can happen on an AVR (usually, setting a bit requires 3 instructions, two registers, and an additional 32bit constant in flash.) It does allow single-bit modifications by having separate SET/CLEAR/TOGGLE registers for each port.
See also This message thread at AdaFruit

@westfw thank you very much for the information. I have found bits an pieces of what you mention along the way but it is nice to have a full picture and explanation to go along. Much appreciated!

@westfw do you know what the difference between REG_PORT_OUTTGL1 and REG_PORT_OUTTGL0 is?

the difference between REG_PORT_OUTTGL1 and REG_PORT_OUTTGL0

OUTTGL1 is portB, OUTTGL0 is portA.

That is

&REG_PORT_OUTTGL0 ==  &PORT->Group[0].OUTTGL.reg
&REG_PORT_OUTTGL1 ==  &PORT->Group[1].OUTTGL.reg