CH32X035G8U6配置UART1之后PB8和PB9无法上拉

CH32X035G8U6配置UART1使用PB10为UART1_TX之后,再去配置PB8和PB9为上拉输入,设置EXTI中断,发现PB8和PB9无法上拉,处于浮空状态,代码使用例程EXTI0所修改。GPIO配置代码如下

void EXTI0_INT_INIT(void)

{

    EXTI_InitTypeDef EXTI_InitStructure = {0};

    NVIC_InitTypeDef NVIC_InitStructure = {0};

    USART_InitTypeDef USART_InitStructure = {0};

    GPIO_InitTypeDef GPIO_InitStructure = {0};


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

    GPIO_Init(GPIOB, &GPIO_InitStructure);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOB, &GPIO_InitStructure);


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);

    USART_InitStructure.USART_BaudRate = 115200;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    USART_InitStructure.USART_Parity = USART_Parity_No;

    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

    USART_InitStructure.USART_Mode = USART_Mode_Tx;


    USART_Init(USART1, &USART_InitStructure);

    USART_Cmd(USART1, ENABLE);



    /* GPIOB ----> EXTI_Line8 */

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);

    EXTI_InitStructure.EXTI_Line = EXTI_Line8;

    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    EXTI_Init(&EXTI_InitStructure);


    /* GPIOB ----> EXTI_Line9 */

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

    EXTI_InitStructure.EXTI_Line = EXTI_Line9;

    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    EXTI_Init(&EXTI_InitStructure);


    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_8_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

}

您好,我这边测试上拉是没问题的,附件为参考例程,可以测试一下。

icon_rar.gifEXAM.zip



你好,我这边看了一下您发的附件,我发现附件内的Debug串口配置的是UART2,您可以试试如下描述。

下面为具体情况的描述:

下面的代码为main.c内部的代码,由例程EXTI0修改得来,请将debug串口改成“DEBUG_UART1”,并将“EXTI0_INT_INIT();”放置在“USART_Printf_Init(115200);”之前可以复现PB8,PB9无法上拉的情况。

(而且“EXTI0_INT_INIT();”放置在“USART_Printf_Init(115200);”之后导致DEBUG_UART1失灵。)


#include "debug.h"

//请将debug串口改成“DEBUG_UART1”

//请将debug串口改成“DEBUG_UART1”

//请将debug串口改成“DEBUG_UART1”


/* Global define */


/* Global Variable */


/*********************************************************************

 * @fn      EXTI0_INT_INIT

 *

 * @brief   Initializes EXTI0 collection.

 *

 * @return  none

 */

void EXTI0_INT_INIT(void)

{

    GPIO_InitTypeDef GPIO_InitStructure = {0};

    EXTI_InitTypeDef EXTI_InitStructure = {0};

    NVIC_InitTypeDef NVIC_InitStructure = {0};


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);


    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

    GPIO_Init(GPIOB, &GPIO_InitStructure);


    /* GPIOA ----> EXTI_Line0 */

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);

    EXTI_InitStructure.EXTI_Line = EXTI_Line8;

    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    EXTI_Init(&EXTI_InitStructure);


    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

    EXTI_InitStructure.EXTI_Line = EXTI_Line9;

    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    EXTI_Init(&EXTI_InitStructure);


    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_8_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

}


/*********************************************************************

 * @fn      main

 *

 * @brief   Main program.

 *

 * @return  none

 */

int main(void)

{

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

    SystemCoreClockUpdate();

    Delay_Init();


    EXTI0_INT_INIT();   //放在USART_Printf_Init(115200)的“前面”会出现PB8,PB9无法上拉,用手触摸会触发中断


    USART_Printf_Init(115200);

    printf("SystemClk:%d\r\n", SystemCoreClock);

    printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

    printf("EXTI0 Test\r\n");

    

//    EXTI0_INT_INIT(); //放在USART_Printf_Init(115200)会出现串口UART1失灵


    while(1)

    {

        Delay_Ms(1000);

        printf("Run at main\r\n");

    }

}


void EXTI15_8_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));


/*********************************************************************

 * @fn      EXTI0_IRQHandler

 *

 * @brief   This function handles EXTI0 Handler.

 *

 * @return  none

 */

void EXTI15_8_IRQHandler(void)

{

  if(EXTI_GetITStatus(EXTI_Line8)!=RESET)

  {

    printf("Run at EXTI8\r\n");

    EXTI_ClearITPendingBit(EXTI_Line8);     /* Clear Flag */

  }

  if(EXTI_GetITStatus(EXTI_Line9)!=RESET)

  {

    printf("Run at EXTI9\r\n");

    EXTI_ClearITPendingBit(EXTI_Line9);     /* Clear Flag */

  }

}



您好,可用附件文件将工程ch32x035_gpio.c文件替换一下,应该可以解决问题

icon_rar.gifch32x035_gpio.zip



只有登录才能回复,可以选择微信账号登录