野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 20997|回复: 3

看视频写GPIO置位复位函数,灯不闪烁,亮一下就灭了

[复制链接]
发表于 2021-8-4 21:57:41 来自手机 | 显示全部楼层 |阅读模式
本帖最后由 zxcvbnm868 于 2021-8-7 22:52 编辑

f407的板子,写了GPIO端口的置位复位函数,单独使用都没问题,放进while循环控制led闪烁,led只亮一下然后熄灭,请问各位大佬是啥问题。
麻烦帮看一下,用注释掉的代码运行led闪烁正常。置位复位单独用,能点亮熄灭led。

int main()
{
        *(unsigned int *)(0x40023830) |= (1<<5);
        GPIO_InitTypeDef GPIO_InitStruct;
        GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_6;
        GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_OUT;
        GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_UP;
        GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init(GPIOF,&GPIO_InitStruct);
        while(1)
        {               
//                GPIOF->ODR &= ~(1<<6);
//                delay(0x2fffff);
                GPIO_ResetBits(GPIOF,GPIO_Pin_6);
                delay(0xfffff);
                GPIO_SetBits(GPIOF,GPIO_Pin_6);
                delay(0xfffff);
        }

}


置位复位函数
void GPIO_SetBits(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)
{
        GPIOx->BSRRL = GPIO_Pin;
}

void GPIO_ResetBits(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)
{
        GPIOx->BSRRH = GPIO_Pin;
}
回复

使用道具 举报

发表于 2021-8-5 16:48:29 | 显示全部楼层
把代码贴出来才好分析问题所在。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-7 22:47:34 | 显示全部楼层
hansome 发表于 2021-8-5 16:48
把代码贴出来才好分析问题所在。

麻烦帮看一下,用注释掉的代码运行led闪烁正常。置位复位单独用,能点亮熄灭led。

int main()
{
        *(unsigned int *)(0x40023830) |= (1<<5);
        GPIO_InitTypeDef GPIO_InitStruct;
        GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_6;
        GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_OUT;
        GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_UP;
        GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init(GPIOF,&GPIO_InitStruct);
        while(1)
        {               
//                GPIOF->ODR &= ~(1<<6);
//                delay(0x2fffff);
                GPIO_ResetBits(GPIOF,GPIO_Pin_6);
                delay(0xfffff);
                GPIO_SetBits(GPIOF,GPIO_Pin_6);
                delay(0xfffff);
        }

}


置位复位函数
void GPIO_SetBits(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)
{
        GPIOx->BSRRL = GPIO_Pin;
}

void GPIO_ResetBits(GPIO_TypeDef * GPIOx,uint16_t GPIO_Pin)
{
        GPIOx->BSRRH = GPIO_Pin;
}
回复 支持 反对

使用道具 举报

发表于 2021-8-9 16:32:46 | 显示全部楼层
zxcvbnm868 发表于 2021-8-7 22:47
麻烦帮看一下,用注释掉的代码运行led闪烁正常。置位复位单独用,能点亮熄灭led。

int main()

你试着用GPIOF->IDR读取,然后再与上~(1<<6),最后再赋值给GPIOF->ODR。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-6-19 11:57 , Processed in 0.032739 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表