2009-10-29 02:40 PM
Set/Reset a pin
2011-05-17 04:28 AM
Hi,
I am new with STM32F10X. Could anyone show me how to set/reset a pin. For example PA3 of STM32F103VBH6. I try GPIO_WriteBits / GPIO_SetBits / GPIO_ResetBits but it does not work? Thank you very much.2011-05-17 04:28 AM
You may need to set up the GPIO pins with GPIOInit(). You need to enable the peripheral clock to the GPIO port with RCC_APB2PeriphClockCmd(). See main.c in the example GPIO_IOToggle in the peripheral library examples.
Once you have that working, if you want, you can just use the set / reset and set registers, #define CLK GPIO_Pin_6 GPIOF->BSRR = CLK; //clock high GPIOF->BRR = CLK; //clock low The advantage of these is that the same bit definition can be used to set or clear a pin depending on whether you write to the BSRR or BRR register. Hope this helps.2011-05-17 04:28 AM
Thanks for your replying.
You are correct. What I did is use: - RCC_APB2PeriphClockCmd - GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_SetBits + GPIO_ResetBits or GPIO_WriteBit To read the data port pin, I use GPIO_ReadInputDataBit. My code works now. Thanks again.