Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Grand Central M4, get status of output pin
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Grand Central M4, get status of output pin

by psg1908 on Tue Jul 07, 2020 12:32 pm

There's a snippet of code I use (originally taken from an Arduino forum post) on an Arduino Mega to read the value of an output pin:

Code: Select all | TOGGLE FULL SIZE
#include <wiring_private.h>
#include <pins_arduino.h>
#define A_PIN 2

bool getDir()
{
 uint8_t bit = digitalPinToBitMask(A_PIN);
 uint8_t port = digitalPinToPort(A_PIN);
 if (port == NOT_A_PIN)
   return LOW;

 return (*portOutputRegister(port) & bit) ? HIGH : LOW;
}

However in transitioning to my M4 this doesn't seem to be supported. Is there a method I can use to get the status of a digital output pin on my Grand Central M4?

To clarify, this is the error I am receiving in compiling the above code:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.13 (Windows 10), Board: "Adafruit Grand Central M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 50 MHz (standard), Arduino, Off"

In file included from <...>\Arduino15\packages\adafruit\hardware\samd\1.5.14\cores\arduino/delay.h:24:0,

                 from <...>\Arduino15\packages\adafruit\hardware\samd\1.5.14\cores\arduino/Arduino.h:81,

                 from sketch

<...>: In function 'bool getDir()':

<...>\Arduino15\packages\adafruit\hardware\samd\1.5.14\variants\grand_central_m4/variant.h:66:38: error: invalid conversion from 'PortGroup*' to 'uint8_t {aka unsigned char}' [-fpermissive]

 #define digitalPinToPort(P)        ( &(PORT->Group[g_APinDescription[P].ulPort]) )

                                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<...>: note: in expansion of macro 'digitalPinToPort'

  uint8_t port = digitalPinToPort(A_PIN);

                 ^~~~~~~~~~~~~~~~

<...>\Arduino15\packages\adafruit\hardware\samd\1.5.14\variants\grand_central_m4/variant.h:69:44: error: base operand of '->' is not a pointer

 #define portOutputRegister(port)   ( &(port->OUT.reg) )

                                            ^

<...>: note: in expansion of macro 'portOutputRegister'

  return (*portOutputRegister(port) & bit) ? HIGH : LOW;

           ^~~~~~~~~~~~~~~~~~

exit status 1

Error compiling for board Adafruit Grand Central M4 (SAMD51).


psg1908
 
Posts: 4
Joined: Tue Jul 07, 2020 12:28 pm

Please be positive and constructive with your questions and comments.