cancel
Showing results for 
Search instead for 
Did you mean: 

Facing problem in GPIO configuration

SS.Sagar
Associate III
Posted on June 08, 2016 at 19:27

Hi,

I m configuring GPIO port for OUTPUT. but, i m not able to configure it propely.

Following is my implmentation which is not working.

GPIOC->CRL |= 0x00000001<<20; // GPIOC-5th

GPIOC->CRL |= 0x00000001<<24; // GPIOC-6th

GPIOC->CRH |= 0x00000001; // GPIOC-8th

GPIOC->CRH |= 0x00000001<<4; // GPIOC-9th

GPIOC->BSRR = 0x00000020;

GPIOC->BSRR = 0x00000000;

GPIOC->BSRR = 0x00000100;

GPIOC->BSRR = 0x00000000;

I checked voltage, bit it is not comping. but if i used following configuration then it is working.

 GPIO_InitTypeDef GPIO_InitStruct;

 GPIO_InitStruct.Pin = GPIO_PIN_5;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_6;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_8;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_9;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

#!stm32 #gpio #nucleo
3 REPLIES 3
Posted on June 08, 2016 at 22:20

Or'ing single bits into a setting that uses multiple, probably prone to fail for non-zero register content.

BSRR = 0 does nothing

Look at the CRx in both cases, are they different? Is MODER different?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SS.Sagar
Associate III
Posted on June 09, 2016 at 05:37

Hi,

I tried without ORing also. like following.

GPIOC->CRL = 0x00000001<<20; // GPIOC-5th

GPIOC->CRL = 0x00000001<<24; // GPIOC-6th

GPIOC->CRH = 0x00000001; // GPIOC-8th

GPIOC->CRH = 0x00000001<<4; // GPIOC-9th

I checked CRx registers too. It seems to be correct.And i m setting 2 pins 

GPIOC->BSRR = 0x00000020;

GPIOC->BSRR = 0x00000100;

Atleast these two pins should be HIGH.

I m using STM32F103xx processor.

Posted on June 09, 2016 at 16:21

The technique typically employed is to AND the register with a mask to clear the bits you want to control, whilst leaving intact everything else, and then OR in the bits you need set. Assuming the register will have bits already set to zero is a flawed assumption.

If you are going to do register level programming you're going to need to be a bit more wily.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..