2021-04-10 06:09 AM
I am only able to use 2 GPIO pins with an STM32F767ZI on a Nucleo-144 board. The issue doesn't appear to be with any specific pins, it's just that only 2 pins seem to output any voltage at all.
Take this code for example:
main.c
#include "./headers/stm32f767xx.h"
#include <stdint.h>
int main(void)
{
initMotor(0);
initMotor(1);
initMotor(2);
uint32_t a = 0;
while (1)
{
if (a >= 25000)
{
stepMotor(0);
stepMotor(1);
stepMotor(2);
a = 0;
}
a++;
}
}
./drivers/motor.c
#include "../headers/stm32f767xx.h"
void initMotor(int step_pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;
GPIOG->MODER |= (0b01 << (step_pin * 2));
GPIOG->OTYPER &= ~(0b1 << step_pin);
GPIOG->ODR &= ~(0b1 << step_pin);
}
void stepMotor(int step_pin)
{
GPIOG->ODR ^= (0b1 << step_pin);
}
Using this code, only 2 of the 3 GPIO ports give out a voltage as I would expect them to. If main.c is modified to remove any of the three motors/pins, the other two will work (they give out a voltage which changes from HIGH to LOW every time period).
This issue extends even when adding LEDs which are already on the board.
Only a maximum of 2 GPIO pins (regardless of whether it is GPIOA, GPIOB, etc.) ever seem to work.
I am very unsure of the cause of this, and would appreciate any direction that people can point me in.
Solved! Go to Solution.
2021-04-12 03:55 AM
Try to remove
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;
from initMotor(), and place it at the beginning of main(). Also try to add a readback of RCC->AHB1ENR after that.
JW
2021-04-10 08:51 AM
Try:
volatile uint32_t a = 0;
JW
2021-04-10 11:14 AM
What kind of loads are you trying to drive?
2021-04-10 02:15 PM
gave that a go, but it made no difference
2021-04-10 02:17 PM
i am using a separate driver, rather than directly powering the motor from the STM32. this driver requires a single pulse to step the motor by one step
2021-04-10 03:34 PM
With 3 pins, make one "step", stop, measure output voltages, and read out and check/post the corresponding GPIO registers values.
You can manipulate the GPIOs in debugger.
JW
2021-04-10 04:54 PM
PG0: 3.30V
PG1: 3.30V
PG2: 0.43V
2021-04-10 07:12 PM
and read out and check/post the corresponding GPIO registers values.
2021-04-11 03:18 AM
0x40021800 (G_MODER)
0x5 - 0000000000000101
0x40021804 (G_TYPER)
0x0 - 0000000000000000
0x40021814 (G_ODR)
0x7 - 0000000000000111
very strange, seems the MODE register isn't setting pin 2 to output
2021-04-11 03:34 AM
and when an additional motor is connected up (so four in total now), the motors connected to GP0 and GP2 spin/step rather than GP0 and GP1, like previously
the voltage output by GP0 and GP2 is 3.30V, whereas GP1 and GP3 output 0V
(yes, the code has been modified to rotate/step this additional motor by adding "initMotor(3);" and "stepMotor(3);")
and once again, the registers reflect this:
0x40021800 (G_MODER)
0x11 - 0000000000010001
0x40021804 (G_TYPER)
0x0 - 0000000000000000
0x40021814 (G_ODR)
0xf - 0000000000001111
i have no clue why the MODE register isn't being set properly