You can see a picture from my trial stand attached to this forum post. I would like to introduce the composition of aggregates and the project content short:
1. A commercially available stepper motor (size: NEMA 23)
2. A digital stepping drive (Type: DM422C, Co.: LEADSHINE)
3. A STM32F103C8T6 on a plug-in board
Now it comes to my objectives and questions:
1. I would like to position the stepper motor in a predefined and accurately way with C++-code.
2. The micro-controller pin out for this composition is:
PA2 (STM32F103C8T6) -> PUL (DM422C)
PA3 -> DIR
PA4 -> ENA
5 V -> OPTO
Additional informations: The PUL-signal structure should be a "single mode"-structure after declarations in the data-sheet (DM422C, page 4).
But now to my inadequacies regarding "information technology" as main field or in particular a simple programming-question (C++) for this sample composition:
I tried for a simple drive of stepper motor in this composition the following code snippet:
RCC->APB2ENR |= 0xFC;
GPIOA->CRL = 0x44433344;
GPIOA->ODR |= (1<<4);
GPIOA->ODR |= (1<<3);
while (1)
{
GPIOA->ODR |= (1<<2);
delay_ms(50);
GPIOA->ODR &= !(1<<2);
delay_ms(50);
}
I would like to open our discussion now. Please be aware that a binary notation in c++-code in look to your answers would be a higher support for me. A minimalistic and working c++-snippet for a stepper motor drive is wished.
A used didactic way in the answers regarding the not working c++-code is also wished.
Have an - in common and below university-student-words - "nice" day or night!
Please excuse my style of post, it is one of my first posts here.
Yours TIMBO 2023
&= !(1<<2)is a mistake. You meant to use bitwise complement~not logical inversion!.As a consequence of this error, you are clearing
DIRandENAevery time you attempt to generate a falling edge onPUL.Try with
You may alternatively choose to use the hardware logic for generating GPIO falling edges, accessed through
and for rising edges
These are better than bitwise manipulations
|=and&=becauseODRFor these reasons, you should only use
ODRwhen you intend to overwrite all pins of the GPIO port, and for changing individual pins or groups, useBSRRandBRR.