Incorrect value when reading GPIOB_IDR register

0

I struggle with stm32f030r8 arm programming on atollic true studio ide.

I have some problem with reading correct data from idr register.

I make pull down PUPR register of GPIOB(0,1,2,3).

Other pins of GPIOB is output that i make with MODER register.

when i read idr data under loop every time i read F value but there is not any input.

Please help me to solve this problem [You can see value that i read when debugging[1]

There is no any input It has to read 0x00

#include "main.h"
int main(void)
{
 volatile static uint16_t PortDataInput=0x00;
 RCC->CR|=(uint32_t)0xF1; //set hsi clock source and with max speed
 GPIOB->PUPDR|=0xAA; //set firt 4 bit of gpiob as pull down
 GPIOB_RCC->AHBENR|=(1<<18); //enable gpiob clock source
 GPIOB->MODER|=0x55555500; //set firt 4 bit of gpiob as input
 GPIOB->OTYPER|=0x00000000; //set output pins of gpiob as push pull
 while (1)
 { 
 PortDataInput=GPIOB->IDR;
 PortDataInput&=0xF;
 }
c
arm
nucleo
stm32f0
asked on Stack Overflow Jun 30, 2019 by Eldar Mahmudov

2 Answers

2

You try to set the gpio register before enabling peripheral clock. So you can't write to any of its registers.

answered on Stack Overflow Jul 1, 2019 by 0___________
0

I found the solution. Solution is that.I had to set all gpio registers after enabling peripheral clock.

#include "main.h"
int main(void)
{
 volatile static uint16_t PortDataInput=0x00;
 RCC->CR|=(uint32_t)0xF1; //set hsi clock source and with max speed
 GPIOB_RCC->AHBENR|=(1<<18); //enable gpiob clock source
 GPIOB->PUPDR|=0xAA; //set firt 4 bit of gpiob as pull down
 GPIOB->MODER|=0x55555500; //set firt 4 bit of gpiob as input
 GPIOB->OTYPER|=0x00000000; //set output pins of gpiob as push pull
while(1)
{
 PortDataInput=GPIOB->IDR;
 PortDataInput&=0xF;
}
answered on Stack Overflow Jul 7, 2019 by Eldar Mahmudov

User contributions licensed under CC BY-SA 3.0