Direct Port Manipulation Using the Arduino Giga Board

Hi All,

I'm using an 8 Bit Absolute encoder for a Inverted Pendulum Project, and I was wondering if I can directly access Pins 22, 24, 26, 28, 30, 32, 34, 36 in Parallel.

In short, I lifted some code which Works as noted below but I would like a more elegant "Byte at one Time" approach.

The DDRD method does not appear to work correctly on this Board.

Thanks for any Advise / Direction!!!

Paul

byte BIN_Test;

byte DDRD;

void setup() {

Serial.begin(9600);

Serial.println("Encoder Test Giga!!!");

pinMode(22, INPUT);
pinMode(24, INPUT);
pinMode(26, INPUT);
pinMode(28, INPUT);
pinMode(30, INPUT);
pinMode(32, INPUT);
pinMode(34, INPUT);
pinMode(36, INPUT);

//PORTD = 0b10101010;
}

void loop() {
//Serial.println("Encoder Test Giga!!!");

BIN_Test =  (digitalRead(22) << 0) +
            (digitalRead(24) << 1) +
            (digitalRead(26) << 2) +
            (digitalRead(28) << 3) +
            (digitalRead(30) << 4) +
            (digitalRead(32) << 5) +
            (digitalRead(34) << 6) +
            (digitalRead(36) << 7);

Serial.println( BIN_Test, DEC );

//Serial.println( DDRD, DEC );

}

3,000 pages...

https://www.st.com/content/ccc/resource/technical/document/reference_manual/group0/82/40/1a/07/c9/16/40/35/DM00176879/files/DM00176879.pdf/jcr:content/translations/en.DM00176879.pdf

Maybe Port manipulation on the new Arduino Giga will help.

Please edit your post, select all code and press the <CODE/> button; next save your post. This will apply code tags as described in How to get the best out of this forum which makes your code easier to read, easier to copy and prevents the forum software from treating (parts of) your code as formatting instructions.

PS
Screenshots of code are about useless. Nobody in his sane mind will type what is in a screenshot to test. Same applies to screenshots of errors (just in case you are tempted to post that).

Hi,

Thanks for the Info!

Do you have a Giga?

What Page has the Decoder Ring that shows How to Access Multiple Ports in one line like the Uno did?

I looked around and Could not Find anywhere.

It makes sense that they would have something that would since ALL Boards that I have ever uses have a similar Command except for the Giga.

Thanks Paul

Previous Uno Code:
PORTD maps to Arduino digital pins 0 to 7

DDRD - The Port D Data Direction Register - read/write

PORTD - The Port D Data Register - read/write

PIND - The Port D Input Pins Register - read only

It might be more useful to look at the Arduino implementation of digitalWrite() first (although maybe not, since I think Arduino runs on top of MBed, which runs on top of the ST HAL code, which adds (several?) levels of abstraction/obfuscation to anything that happens.

arduino-giga-r1-wifi

Can you switch to D25, D27, D29, D31, D33, D35, D37, D38?

You might get away with

auto val = GPIOJ->IDR;
To make PIN22 an INPUT (PJ12)
GPIOJ->MODER &= ~(0x03<<24)

To make PIN24 an INPUT (PG12)
GPIOG->MODER &= ~(0x03<<24)

Hi,

Thanks for you Advise!!!

I have been reviewing the Giga_RM0399_Reference_Manual and I am confused on the Exact Syntax to write out a Byte at a Time.

On Pages 578 its states “The peripheral registers can be written in word, half word or byte mode”
I modified the Test Code you Provided I can measure any Voltage on Pin 22 or any of the other Pins.

What am I doing wrong?

Also it appears that the Documentation I have is different than yours.

As noted below it "Reset value: 0xFFFF FFFF for other ports".

What Year is yours from the one I have is from "June 2023"

Thanks Paul

void loop() {
//Serial.println("Encoder Test Giga Direct Port Manipulation!!!");

GPIOJ->MODER |= ~(0x03<<24);

BIN_Test = GPIOJ->MODER;

Serial.println( BIN_Test, HEX );

}

You are reading the current configuration (INPUT or OUTPUT) of the pin.

Does it work better with IDR?

Few of the processors I've seen that have those "port can be written in word, halfword, or byte mode" registers actually bother to define symbols for writing them an anything other than word mode. For instance, off in stm32h747xx.h there is this definition for the IO port:

typedef struct
{
  __IO uint32_t MODER;    /*!< GPIO port mode register,               Address offset: 0x00      */
  __IO uint32_t OTYPER;   /*!< GPIO port output type register,        Address offset: 0x04      */
  __IO uint32_t OSPEEDR;  /*!< GPIO port output speed register,       Address offset: 0x08      */
  __IO uint32_t PUPDR;    /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
  __IO uint32_t IDR;      /*!< GPIO port input data register,         Address offset: 0x10      */
  __IO uint32_t ODR;      /*!< GPIO port output data register,        Address offset: 0x14      */
  __IO uint32_t BSRR;     /*!< GPIO port bit set/reset,               Address offset: 0x18      */
  __IO uint32_t LCKR;     /*!< GPIO port configuration lock register, Address offset: 0x1C      */
  __IO uint32_t AFR[2];   /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
} GPIO_TypeDef;

All word-wide access!

To do byte-style access, you would have to do a bit of pointer manipulation:

  uint8_t value = * (  (uint8_t*)&GPIOJ->IDR ) + 3);

// or
  uint8_t * portjPtr = (uint8_t*)&GPIOJ->IDR;   // pointer to base of IO regsiter.
  uint8_t lsb = portPtr[0];
  uint8_t msb = portPtr[3];

Hi All,

After Hours and Hours of Research, I wrote this Working Program for use on the GIGA Board.

Let me know if you have any Questions.

Thanks Paul

//********************
//********************
//********************
// This Program Outputs a Byte to "GIOJ" Ports: D38 (PJ7), D37 (PJ6), D35 (PJ5), D33 (PJ4), D31 (PJ3), D29 (PJ2), D27 (PJ1), D25 (PJ0) 
//********************
//********************
//********************

//Set Byte_Test to Word for "Serial.println"
word Byte_Test;

void setup() {

  Serial.begin(9600);

  Serial.println("Encoder Test --> Giga Direct Port Manipulation!!!");

//********************
//********************
//********************

//Set Desired Byte Pins to OUTPUT
  pinMode(25, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(31, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(35, OUTPUT);
  pinMode(37, OUTPUT);
  pinMode(38, OUTPUT);

}

void loop() {
 //Serial.println("Encoder Test Giga Direct Port Manipulation!!!"); 

//********************
//********************
//********************

//Copy 'n' Paste Code that Actually Works!!!!
//GPIOJ->ODR = (0b00000001); // Turns on: D25 (PJ0)
//GPIOJ->ODR = (0b00000010); // Turns on: D27 (PJ1)
//GPIOJ->ODR = (0b00000011); // Turns on: D27 (PJ1), D25 (PJ0)
//GPIOJ->ODR = (0b00000100); // Turns on: D29 (PJ2)
//GPIOJ->ODR = (0b00000101); // Turns on: D29 (PJ2), D25 (PJ0)
//GPIOJ->ODR = (0b00000110); // Turns on: D29 (PJ2), D27 (PJ1)
//GPIOJ->ODR = (0b00000111); // Turns on: D29 (PJ2), D27 (PJ1), D25 (PJ0) 
//GPIOJ->ODR = (0b00001000); // Turns on: D31 (PJ3)
//GPIOJ->ODR = (0b00001001); // Turns on: D31 (PJ3), D25 (PJ0)
//GPIOJ->ODR = (0b00001010); // Turns on: D31 (PJ3), D27 (PJ1)
//GPIOJ->ODR = (0b00001011); // Turns on: D31 (PJ3), D27 (PJ1), D25 (PJ0)
//GPIOJ->ODR = (0b00001100); // Turns on: D31 (PJ3), D29 (PJ2)
//GPIOJ->ODR = (0b00001101); // Turns on: D31 (PJ3), D29 (PJ2), D25 (PJ0)
//GPIOJ->ODR = (0b00001110); // Turns on: D31 (PJ3), D29 (PJ2), D27 (PJ1)
//GPIOJ->ODR = (0b00001111); // Turns on: D31 (PJ3), D29 (PJ2), D27 (PJ1), D25 (PJ0)
//   *
//   *
//   *
//GPIOJ->ODR = (0b11111111); // Turns on: D38 (PJ7), D37 (PJ6), D35 (PJ5), D33 (PJ4), D31 (PJ3), D29 (PJ2), D27 (PJ1), D25 (PJ0)

//********************
//********************
//********************

//Set GIPO "J" Port to Desired Byte
//This Turns On / Off Desired Digital Ports
GPIOJ->ODR = (0b00000111); // Turns on: D29 (PJ2), D27 (PJ1), D25 (PJ0) 

//Set "Byte_Test" to Desired Byte
Byte_Test =  (GPIOJ->ODR);

//Prints "Byte_Test" to "Serial Monitor" in HEX      
Serial.println( Byte_Test, HEX );

}

Hi,

Thanks for you Input!!!

Using your Idea I was able to Sove by Further Investigation / Testing.

Thanks Paul

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.