# Direct Port Manipulation Using the Arduino Giga Board

**URL:** <https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805>\
**Category:** Programming\
**Created:** [April 2, 2024, 2:50am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805 "2024-04-02T02:50:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazyjaws69](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crazyjaws69](https://forum.arduino.cc/u/crazyjaws69)\
**Post date:** [April 2, 2024, 2:50am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/1 "2024-04-02T02:50:23Z")

</div>

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](https://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 );

```

}

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [April 2, 2024, 3:16am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/2 "2024-04-02T03:16:58Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 2, 2024, 5:31am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/3 "2024-04-02T05:31:29Z")

</div>

Maybe [Port manipulation on the new Arduino Giga](https://forum.arduino.cc/t/port-manipulation-on-the-new-arduino-giga/1100435) 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](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966) 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).

---

<div class="post-metadata">

**Author:** ![crazyjaws69](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crazyjaws69](https://forum.arduino.cc/u/crazyjaws69)\
**Post date:** [April 2, 2024, 7:33pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/4 "2024-04-02T19:33:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [April 2, 2024, 7:48pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/5 "2024-04-02T19:48:28Z")

</div>

> [@crazyjaws69](#):
>
> What Page has the Decoder Ring that shows How to Access Multiple Ports in one line like the Uno did?

> [@Port manipulation for the Arduino Giga](https://forum.arduino.cc/t/port-manipulation-for-the-arduino-giga/1172151/6):
>
> You need to look at ST's document [RM0399](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) - Reference Manual for STM32H747XI See chapter 12, page 568 / 3556.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [April 2, 2024, 9:39pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/6 "2024-04-02T21:39:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rintin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rintin/32/1013044_2.png) [@Rintin](https://forum.arduino.cc/u/Rintin)\
**Post date:** [April 2, 2024, 11:19pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/7 "2024-04-02T23:19:49Z")

</div>

![arduino-giga-r1-wifi](https://europe1.discourse-cdn.com/arduino/original/4X/a/9/7/a975c1c3690a7f53be1e9942bb1aca12805adebb.png)

Can you switch to D25, D27, D29, D31, D33, D35, D37, D3 **8**?

You might get away with

```arduino
auto val = GPIOJ->IDR;
```

---

<div class="post-metadata">

**Author:** ![hzrnbgy](https://avatars.discourse-cdn.com/v4/letter/h/90db22/32.png) [@hzrnbgy](https://forum.arduino.cc/u/hzrnbgy)\
**Post date:** [April 3, 2024, 1:05am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/8 "2024-04-03T01:05:55Z")

</div>

```arduino
To make PIN22 an INPUT (PJ12)
GPIOJ->MODER &= ~(0x03<<24)

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

```

---

<div class="post-metadata">

**Author:** ![crazyjaws69](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crazyjaws69](https://forum.arduino.cc/u/crazyjaws69)\
**Post date:** [April 8, 2024, 6:23pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/9 "2024-04-08T18:23:18Z")

</div>

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](https://Serial.println)("Encoder Test Giga Direct Port Manipulation!!!");

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

BIN\_Test = GPIOJ-\>MODER;

Serial.println( BIN\_Test, HEX );

}

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/8/a/4/8a4487e5cdbacc6d6f49779e24bfdbfbebb5ca12.png)

---

<div class="post-metadata">

**Author:** ![Rintin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rintin/32/1013044_2.png) [@Rintin](https://forum.arduino.cc/u/Rintin)\
**Post date:** [April 8, 2024, 6:58pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/10 "2024-04-08T18:58:50Z")

</div>

> [@crazyjaws69](#):
>
> BIN\_Test = GPIOJ-\>MODER;

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

Does it work better with IDR?

> [@crazyjaws69](#):
>
> BIN\_Test = GPIOJ-\>IDR;

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [April 8, 2024, 7:48pm UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/11 "2024-04-08T19:48:46Z")

</div>

> [@crazyjaws69](#):
>
> “The peripheral registers can be written in word, half word or byte mode”

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:

```arduino
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:

```arduino
  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];

```

---

<div class="post-metadata">

**Author:** ![crazyjaws69](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crazyjaws69](https://forum.arduino.cc/u/crazyjaws69)\
**Post date:** [April 14, 2024, 2:08am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/12 "2024-04-14T02:08:43Z")

</div>

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

```arduino
// ********************
// ********************
// ********************
// 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 );

}

```

---

<div class="post-metadata">

**Author:** ![crazyjaws69](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@crazyjaws69](https://forum.arduino.cc/u/crazyjaws69)\
**Post date:** [April 14, 2024, 2:17am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/13 "2024-04-14T02:17:40Z")

</div>

Hi,

Thanks for you Input!!!

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

Thanks Paul

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 11, 2024, 2:18am UTC](https://forum.arduino.cc/t/direct-port-manipulation-using-the-arduino-giga-board/1242805/14 "2024-10-11T02:18:37Z")

</div>

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