Page 1 of 1

How to translate Port Manipulation code from Arduino to STM32?

Posted: Wed Mar 23, 2022 5:38 am
by UsamaMechE
I have a code for Arduino UNO that uses port manipulation. However, the code does not compile for STM32 Nucleo F103RB. The error says that the Ports are not defined.

What does a code like:

PORTB = (PORTB & B11111100) | ((d) & B00000011);

mean and how can I translate it to make it work with my Nucleo board?

Re: How to translate Port Manipulation code from Arduino to STM32?

Posted: Wed Mar 23, 2022 6:11 am
by ag123

Re: How to translate Port Manipulation code from Arduino to STM32?

Posted: Wed Mar 23, 2022 4:22 pm
by GonzoG
STM32 have 16 port per register so you'll need to change Arduino code to account for that.

Output registers are GPIOx->ODR (eg. GPIOA->ODR)
Input registers are GPIOx->IDR