2019-10-01 01:21 PM
Hi, This is sureshkumar, I bought one STM32 popular udemy course, on that course have one video that trainer shows some registers to set the pin directions. but my data sheet is showing different name of the register. on that video showing MODE register (0-31), But mine is showing like this
"Each of the general-purpose I/O ports has two 32-bit configuration registers (GPIOx_CRL,GPIOx_CRH)" like 2 words 0-15 and 16-31
And Finally What is the meaning of Push Pull output ?.
Find the attachment CRL,CRH instead of MODE Register.
//PA5
//APB2
//RCC_APB2ENR For Port A to access = 0x00000004
//GPIOx_CRL and GPIOx_CRH
//GPIOx_ODR
#include "stm32f10x.h" // Device header
void delay(int para);
int main(void){
RCC->APB2ENR |= 0x100;
RCC->APB2RSTR |= 0x1;
GPIOA->CRH |= 0x30000;
GPIOA->CRL |= 0x00000;
while(1){
GPIOA->ODR |= 0x10;
delay(100);
GPIOA->ODR |= 0x00;
delay(100);
}
}
void delay(int para){
for(; para>0; para--){
for(int i=10000; i<10000; i--);
}
}
What is the wrong in this program ?. this just try to blink the LED PA5
2019-10-01 02:03 PM
No need to "like" your own post.
There are many STM32 families, the F1 being the oldest.
Push-Pull the output uses both P and N transistors to alternately connect VCC or GND to the output. See diagram "Basic structure of a standard I/O port bit" in RM
Register level code requires a mastery of the Reference Manual (RM), and the use of a debugger to inspect what you've done.
>>What is the wrong in this program ?
It's a mess
Looks like you're not enabling the right GPIO clock (G), and holding another peripheral in reset (AFIO).
Delay loops should use volatile for the iterating variable so as not to have it optimized away.
Step the code, inspect the registers.
Or'ing something with ZERO has no helpful effect. Toggle pin with GPIOA->ODR ^= 0x20; // PA5 Or clear GPIOA->ODR &= ~0x20; // tilde (forum looks like minus, should copy ok)
PA5 is (1 << 5) not (1 << 4)
CR I think you are configuring PA4
2019-10-01 03:00 PM
In addition to what Clive points out, this loop will run for exactly 0 iterations since the starting value doesn't meet the condition.
for(int i=10000; i<10000; i--);
}
You probably meant this:
for (volatile int i=0; i<10000; i++);
}
2019-10-02 12:52 AM
My guess is that you're fairly new to the C programming language as well as stm32 microcontrollers. There's a lot to learn, but by experimenting, looking at the reference manual and asking here you're doing the right thing.
Clive is right to say that you are "Or'ing".
All of what I guess you mean to be assignment statements are of the form "variable |= value"
The vertical bar "|" means a bitwise-or between two values.
A simple assignment would be "=" rather than "|=". (And test-for-equality in C is "==")
So you might ask, which two values? They are the current value in the variable and your new value.
"variable |= value" is just C shorthand for "variable = variable | value"
As to your modifying things like RCC->APB2ENR, I don't think any of us remember which bit is which in these registers. The include file #include "stm32f10x.h" or one of the more-specific files it includes contain useful definitions so you never have to, such as RCC_APB2ENR_IOPAEN. And yes it is annoying that ST change the format of these names from time to time and from family to family e.g. RCC_AHB1ENR_GPIOAEN on stm32f4, but it is easier to spot an error than e.g. 0x100
Hope this helps,
Danish
2019-10-02 10:53 AM
"My guess is that you're fairly new to the C programming language as well as stm32 micro controllers. "
Yes I am new to STM32 only not to "C". I forgot some C syntax that's all. I need to refresh it.
variable |= value this means not affect any other value before set. it just affect the particular bit. the remaining is will be same.
Example
0x202C = 0000 0000 0000 0000 0010 0000 00010 1100. correct ?
Now I want to affect 31th bit(Means I want to set only one 32th bit changed from '0' to '1' with out affect other bits. Then What i need to do ? then it will create that bit wise OR operator.
Previous value in this register
APB2ENR = 0x202C
0000 0000 0000 0000 0010 0000 00010 1100
1000 0000 0000 0000 0010 0000 00010 1100 (|) OR ed with.
-----------------------------------------------------------------
1000 0000 0000 0000 0010 0000 00010 1100
After this | Pipe symbol
the value will be in this APB2ENR register = 0x8000202C.
31th bit only I affect. I the remaining bits are same.
"variable |= value"
That is not a variable. that is register.
Thanks for helping...