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?
How to translate Port Manipulation code from Arduino to STM32?
-
- Posts: 3
- Joined: Sun Dec 19, 2021 5:43 pm
Re: How to translate Port Manipulation code from Arduino to STM32?
you need to review the ref manual rm0008
and a google search would bring up the related example codes and materials e.g.
https://www.google.com/search?q=stm32+g ... a+register
http://fastbitlab.com/gpio-input-data-register/
http://fastbitlab.com/gpio-output-data-register/
https://gist.github.com/iwalpola/6c36c9 ... 0a118571ca
https://controllerstech.com/stm32-gpio- ... registers/
and a google search would bring up the related example codes and materials e.g.
https://www.google.com/search?q=stm32+g ... a+register
http://fastbitlab.com/gpio-input-data-register/
http://fastbitlab.com/gpio-output-data-register/
https://gist.github.com/iwalpola/6c36c9 ... 0a118571ca
https://controllerstech.com/stm32-gpio- ... registers/
Re: How to translate Port Manipulation code from Arduino to STM32?
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
Output registers are GPIOx->ODR (eg. GPIOA->ODR)
Input registers are GPIOx->IDR