Particle Photon Port Manipulation

Hello all,

I’m trying to control my particle photon by interacting directly with the control registers. I’ve been trying to control the on board LED pin D7 as it is the most convenient feedback available.

I did some research into the microprocessor and the GPIO pins/ports.

The LED pin (D7) is assigned to pin PA13 on the actual STM32 microprocessor. PA13 belongs to Port A. In the STM datasheet, they refer to the ports/registers as GPIOx_function where x=A-I (A in our case) and function is the name of the different register (different registers that set pin mode/read/write)

For starters I’m trying to set the D7 pin to be an output, As far as I know, this is done using the MODER register (GPIOA_MODER). The register is 32 bits long, saving two bits per pin (01 refers to the pin being set to output).

After setting it to an output, I’m trying to write a digital high on the pin using the IDR register (GPIOA_ODR) (ODR standing for output data register).

I’m having issues with actually implementing this using the particle build. If anyone has done something similar or can point me in a direction, I would be forever grateful.

I know I can use pinMode and then use digitalWrite or even digitalWriteFast. I am only interested in controlling the pins through their respective control registers.

Many thanks in advance!

What are the issues you are seeing?

It’s always best to be prcise when asking to get precise answers

BTW: While it’s good to know how the bare metal way goes, using the higher level functions will rid you of the need to rework the code when moving from one device (e.g. Photon) to another (e.g. RedBear Duo).

However, if I just use my guessing powers :crystal_ball: you might want to give this a try GPIOA->MODER = ... :wink:

1 Like

Thanks a lot! This actually solved the matter. I’ve been trying different configurations for assigning the register as I believed it to be GPIOA_MODER. Anyways, I really appreciate the help.

As for the simplicity, yes, the higher level functions will solve that but for my specific application I needed to work with the bare registers.

1 Like