串口上位機發(fā)送數(shù)據(jù)給CH32V003會觸發(fā)設(shè)置的EXTI_Line4中斷響應(yīng)

代碼如下,設(shè)置中斷監(jiān)聽PD4上的按鈕按下事件,當(dāng)按鈕事件發(fā)生令LED閃爍(PD2), 但是當(dāng)我用上位機給mcu串口發(fā)送信息,也會觸發(fā)該中斷從而引發(fā)LED閃爍.串口引腳為PD5,PD6,USB轉(zhuǎn)串口的芯片為CH340E.

代碼如下:

/**********************************?(C)?COPYRIGHT?*******************************
?*?File?Name??????????:?main.c
?*?Author?????????????:?WCH
?*?Version????????????:?V1.0.0
?*?Date???????????????:?2022/08/08
?*?Description????????:?Main?program?body.
?*?Copyright?(c)?2021?Nanjing?Qinheng?Microelectronics?Co.,?Ltd.
?*?SPDX-License-Identifier:?Apache-2.0
?*******************************************************************************/

#include?"debug.h"

void?INIT()
{
INTERRUPT_INIT();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,?ENABLE);
GPIO_INIT(GPIOD,GPIO_Pin_2,?GPIO_Mode_Out_PP);
GPIO_WriteBit(GPIOD,?GPIO_Pin_2,?Bit_RESET);
}

void?INTERRUPT_INIT(){

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO?|?RCC_APB2Periph_GPIOD,?ENABLE);
GPIO_InitTypeDef?GPIO_InitStructure?=?{0};
EXTI_InitTypeDef?EXTERNAL_EXTI_InitStructure?=?{0};
NVIC_InitTypeDef?NVIC_InitStructure?=?{0};


GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPD;?//?pull?down
GPIO_Init(GPIOD,?&GPIO_InitStructure);

????/*?PD4?---->?EXTI_Line4?*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,?GPIO_PinSource4);
EXTERNAL_EXTI_InitStructure.EXTI_Line?=?EXTI_Line4;
EXTERNAL_EXTI_InitStructure.EXTI_Mode?=?EXTI_Mode_Interrupt;
EXTERNAL_EXTI_InitStructure.EXTI_Trigger?=?EXTI_Trigger_Rising;
EXTERNAL_EXTI_InitStructure.EXTI_LineCmd?=?ENABLE;
EXTI_Init(&EXTERNAL_EXTI_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel?=?EXTI7_0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?2;
NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void?EXTI7_0_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast")));

/*********************************************************************
?*?@fn??????EXTI0_IRQHandler
?*
?*?@brief???This?function?handles?EXTI0?Handler.
?*
?*?@return??none
?*/
void?EXTI7_0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4)!=RESET)
{
EXTI_ClearITPendingBit(EXTI_Line4);?????/*?Clear?Flag?*/
LED_Blink();
}?
}


void?LED_Blink(){
u8?i?=?6;
while(i--){
GPIO_WriteBit(GPIOD,?GPIO_Pin_2,?Bit_SET);
Delay_Ms(300);
GPIO_WriteBit(GPIOD,?GPIO_Pin_2,?Bit_RESET);
Delay_Ms(300);
}
}
/*********************************************************************
?*?@fn??????GPIO_INIT
?*
?*?@brief???Initializes?GPIO?by?given?params
?*
?*?@return??none
?*/
void?GPIO_INIT(GPIO_TypeDef?*GPIOx,?u16?PIN_NUM,?GPIOMode_TypeDef?IO_MODE)
{
GPIO_InitTypeDef?GPIO_InitStructure?=?{0};
GPIO_InitStructure.GPIO_Pin?=?PIN_NUM;
GPIO_InitStructure.GPIO_Mode?=?IO_MODE;
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_10MHz;
GPIO_Init(GPIOx,?&GPIO_InitStructure);
}

/*********************************************************************
?*?@fn??????main
?*
?*?@brief???Main?program.
?*
?*?@return??none
?*/
int?main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_Init();
INIT();
while(1);
}



熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

您好,可通過示波器監(jiān)控串口PD5,PD6收發(fā)過程中PD4的電平變化。確定問題是否與硬件相關(guān),詳細(xì)測試情況可通過郵箱溝通zl@wch.cn


解決了,我的PCB分了字母板,mcu和串口芯片都在子板,但是PD4的下拉電阻在母版,單獨調(diào)試子板,示波器上看PD4大概有980mv電壓,插上母板調(diào)試后正常.

但是奇怪的是我用評估板相同的代碼PD4懸空電壓也為0.


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

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