2016-06-08 10:27 AM
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 #nucleo2016-06-08 01:20 PM
Or'ing single bits into a setting that uses multiple, probably prone to fail for non-zero register content.
BSRR = 0 does nothingLook at the CRx in both cases, are they different? Is MODER different?2016-06-08 08:37 PM
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-9thI 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.2016-06-09 07:21 AM
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.