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

CH32X035G8U6配置UART1使用PB10為UART1_TX之后,再去配置PB8和PB9為上拉輸入,設(shè)置EXTI中斷,發(fā)現(xiàn)PB8和PB9無法上拉,處于浮空狀態(tài),代碼使用例程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



你好,我這邊看了一下您發(fā)的附件,我發(fā)現(xiàn)附件內(nèi)的Debug串口配置的是UART2,您可以試試如下描述。

下面為具體情況的描述:

下面的代碼為main.c內(nèi)部的代碼,由例程EXTI0修改得來,請將debug串口改成“DEBUG_UART1”,并將“EXTI0_INT_INIT();”放置在“USART_Printf_Init(115200);”之前可以復(fù)現(xiàn)PB8,PB9無法上拉的情況。

(而且“EXTI0_INT_INIT();”放置在“USART_Printf_Init(115200);”之后導(dǎo)致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)的“前面”會出現(xiàn)PB8,PB9無法上拉,用手觸摸會觸發(fā)中斷


? ? 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)會出現(xiàn)串口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文件替換一下,應(yīng)該可以解決問題

icon_rar.gifch32x035_gpio.zip



只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频