How to translate Port Manipulation code from Arduino to STM32?

Post here first, or if you can't find a relevant section!
Post Reply
UsamaMechE
Posts: 3
Joined: Sun Dec 19, 2021 5:43 pm

How to translate Port Manipulation code from Arduino to STM32?

Post 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?
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

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

Post 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
Post Reply

Return to “General discussion”