打印
[STM32F1]

改后一直输出低电平

[复制链接]
835|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huanghuac|  楼主 | 2016-5-29 17:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

void Init_All_Periph(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        RCC_Configuration();
        #if  1
        GPIO_Configuration();
        NVIC_Configuration();
        #else
        /* Configure CAN pin: RX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        /* Configure CAN pin: TX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

//  /* enabling interrupt */
        NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;// USB_LP_CAN_RX0_IRQChannel;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        #endif

}


void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        /* Configure CAN pin: RX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        /* Configure CAN pin: TX */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);


}

//系统中断管理
void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;

        /* Configure the NVIC Preemption Priority Bits */
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

#if  0
#ifdef  VECT_TAB_RAM
        /* Set the Vector Table base location at 0x20000000 */
        NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
        /* Set the Vector Table base location at 0x08000000 */
        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
#endif        

//  /* enabling interrupt */
        NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;// USB_LP_CAN_RX0_IRQChannel;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

}
把上面的函数Init_All_Periph中#if   1时, cantx可以正常输出电平, 改成#if  0后, cantx一直输出低电平, 其他的程序都没有变的情况下.
沙发
happy_10| | 2016-5-29 17:37 | 只看该作者
没看出什么区别;

使用特权

评论回复
板凳
冰清玉洁| | 2016-5-29 17:38 | 只看该作者

void GPIO_Configuration(void)
这个函数里,就多了一个IF;

使用特权

评论回复
地板
zhuhuis| | 2016-5-29 17:39 | 只看该作者

但这段程序是不影响的;

猜不出来啥问题了;

使用特权

评论回复
5
huanghuac|  楼主 | 2016-5-29 17:40 | 只看该作者
那个是被注释掉的!

使用特权

评论回复
6
tian111| | 2016-5-29 17:41 | 只看该作者
程序看起来是一样的呀。
程序跑起来,看看实际寄存器配置的情况。

使用特权

评论回复
7
huanghuac|  楼主 | 2016-5-29 17:42 | 只看该作者
嗯,知道了,周末快乐

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

772

主题

8473

帖子

6

粉丝