-
GD32F303RCT6 USART0的空闲中断进不去,仿真打断点也进不去中断
int main(void) { //¿ÉÒÔ×öµ½´«ÊäÊý¾Ý³öÀ´£¬¶¨µã´«ÊäÊý¾Ý³öÀ´ uint32_t Status2 =0; uint32_t Status3; uint16_t x; dma_parameter_struct dma_init_struct2; gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE); //ÏÂÔØ¿ÚNJTRSTÒý½Åµ±×öÆÕͨI/O¿Ú rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1); systick_config(); //1ms systick gpio_config(); //PA1,PA2,PA3¹Ü½ÅÅäÖà /************************************************/ //UART0_init rcu_periph_clock_enable(RCU_AF);//Need!!!! //usart_halfduplex_enable(USART0); rcu_periph_clock_enable(RCU_USART0); //ʹÄÜUSART0ʱÖÓ gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE); usart_deinit(USART0); //³õʼ»¯ //¸´Î»Ê±ÖÓ usart_baudrate_set(USART0, 19200U); //¶¨Ò岨ÌØÂÊ usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); //·¢ËÍʹÄÜ usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖÐ¶Ï usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖÐ¶Ï usart_enable(USART0); //Ä£¿éʹÄÜ USART_INT_TC nvic_irq_enable(USART0_IRQn, 0, 1); RX0_DMAquest_StartOrInit(); TX0_DMAquest_StartOrInit(); usart_dma_receive_config(USART0, USART_DENR_ENABLE); usart_dma_transmit_config(USART0, USART_DENT_ENABLE); //NVICEXTI_config(); // timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0); // timer_interrupt_enable(TIMER0, TIMER_INT_CH0); // usart_dma_transmit_config(USART0, USART_DENT_ENABLE); // usart_dma_receive_config(USART0, USART_DENR_ENABLE); /******************************************************/ /* configure DMA mode */ // dma_circulation_disable(DMA1, DMA_CH4); //²»Ñ»· rcu_periph_clock_enable(RCU_CRC); gpio_bit_set(GPIOB, GPIO_PIN_5); dma_parameter_struct dma_init_struct; while(1) { // if(++Tx_Delay >= 0x300) // { // Tx_Delay=0; // usart_dma_transmit_config(UART3, USART_DENT_DISABLE); // dma_channel_disable(DMA1, DMA_CH2); //¹Ø±ÕRx // dma_channel_enable(DMA1, DMA_CH2); // usart_dma_transmit_config(UART3, USART_DENT_ENABLE); //6E 32 2E 76 61 6C 3D 31 32 33 ff ff ff delay_1ms(500); if(rxflag) { rxflag=0; dma_parameter_struct dma_init_struct; rcu_periph_clock_enable(RCU_DMA0); //¿ªÊ±ÖÓ dma_deinit(DMA0, DMA_CH3); //³õʼ»¯Í¨µÀ3 dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; //ÄÚ´æµ½ÍâÉè dma_init_struct.memory_addr = (uint32_t)&MyBuffRxUart3[0]; //¶¨Ò建³åÇøhostMainControl Uart3transmitt_buff dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; // dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; //8λλ¿í dma_init_struct.number = 20;//ARRAYNUM(transmitter_buffer); //ÕâÀïÊÇ·¢ËÍÊý¾ÝµÄÊýÁ¿ dma_init_struct.periph_addr = ((uint32_t)0x40013804); //´®¿ÚµØÖ· dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; //¶¨¼Ä´æÆ÷ dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; //8λλ¿í dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; //×î¸ßÓÅÏȼ¶ dma_init(DMA0, DMA_CH3, &dma_init_struct); dma_circulation_disable(DMA0, DMA_CH3); dma_channel_enable(DMA0, DMA_CH3); } 中断如下: extern void RX0_DMAquest_StartOrInit(void); extern uint8_t rxflag; extern dma_parameter_struct dma_data_parameter; void USART0_IRQHandler(void) { uint32_t clear; if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC)) //·¢ËÍcomplete±ê־λΪ1 { /* transmit data */ usart_flag_clear(USART0, USART_FLAG_TC); dma_channel_disable(DMA0, DMA_CH3); // usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖÐ¶Ï // usart_interrupt_disable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖÐ¶Ï dma_channel_enable(DMA0, DMA_CH3); gpio_bit_reset(GPIOB, GPIO_PIN_5); //µãÁÁLED } if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) //·¢ËÍnuLL±ê־λΪ1 { dma_channel_disable(DMA0, DMA_CH4); clear= USART_STAT0(USART0); clear = USART_DATA(USART0); usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ usart_dma_receive_config(USART0, USART_DENR_ENABLE); RX0_DMAquest_StartOrInit(); dma_channel_enable(DMA0, DMA_CH4); // usart_interrupt_disable(USART0, USART_INT_IDLE); //¿ÕÏÐÖÐ¶Ï // usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖÐ¶Ï rxflag=1; } }
1696浏览量 10回复量 关注量 -
GD32f303rct6 RTC问题。
我准备用兆易的GD32F103rct6,RTC时钟,它的时钟32.768晶振的选择是不是和STM32F103一样容易出现问题,不起振?在选择晶振时应注意什么?
3472浏览量 10回复量 关注量 -
GD32为什么用PA2代替key按键功能不成功
配置PA4 ADC引脚,将PA2代替key功能,一脚接地一脚接PA2,想实现在另一key按键控制oled屏同时(使用了PA1),如果杜邦线连接了地与PA2,可以在oled屏幕上显示读取的ADC值程序如下 运行无误但是PA2连接时无法实现预期功能,PA1正常运行 请大佬解答~谢谢 #include "gd32f30x.h" #include "systick.h" #include
#include "oled.h" extern uint8_t IntFlag;//进入中断服务程序标志,在EXTI1_IRQHandler()函数置位 // 定义一个变量来跟踪当前显示的行 static uint8_t currentLine = 0; // 定义一个数组来存储要显示的信息的索引或字符串指针 static const uint8_t chineseMessages[][2] = { {12, 0}, // {30, 1}, // {48, 2}, // {66, 3}, // {84, 4}, // {102, 5} // }; static uint8_t *englishMessages[] = { "HUZHOU", "TEL:12345678" }; uint16_t adc_value; uint16_t Vol_Value; float Vol_Value1; void adc_config(void) { /* reset ADC */ adc_deinit(ADC1); // /* ADC mode config */ adc_mode_config(ADC_MODE_FREE); /* ADC continous function enable */ adc_special_function_config(ADC1, ADC_CONTINUOUS_MODE, ENABLE); /* ADC data alignment config */ adc_data_alignment_config(ADC1, ADC_DATAALIGN_RIGHT); /* ADC resolusion 6B */ // adc_resolution_config(ADC1, ADC_RESOLUTION_6B); /* ADC channel length config */ adc_channel_length_config(ADC1, ADC_REGULAR_CHANNEL, 1); /* ADC regular channel config */ adc_regular_channel_config(ADC1, 0, ADC_CHANNEL_4, ADC_SAMPLETIME_55POINT5); /* ADC trigger config */ adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE); adc_external_trigger_config(ADC1, ADC_REGULAR_CHANNEL, ENABLE); /* enable ADC interface */ adc_enable(ADC1); delay_1ms(1); /* ADC calibration and reset calibration */ adc_calibration_enable(ADC1); /* enable ADC interface */ // adc_software_trigger_enable(ADC0,ADC_REGULAR_CHANNEL); } int main(void) { rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);//设置主频120M(#define __SYSTEM_CLOCK_120M_PLL_HXTAL (uint32_t)(120000000),8M外部晶振 (#define HXTAL_VALUE ((uint32_t)8000000)) systick_config();//1ms systick rcu_periph_clock_enable(RCU_AF); //AF时钟使能 delay_1ms(1000);//等待1000ms gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE);//下载口NJTRST引脚当做普通I/O口 rcu_periph_clock_enable(RCU_GPIOB);//PB时钟使能 gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);//PB4配置成输出 //配置PA4 ADC引脚 rcu_periph_clock_enable(RCU_GPIOA); gpio_init(GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_4); /* enable ADC1 clock */ rcu_periph_clock_enable(RCU_ADC1); /* config ADC clock */ rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV8); //配置ADC adc_config(); adc_software_trigger_enable(ADC1, ADC_REGULAR_CHANNEL); OLED_Init();//OLED初始化 OLED_Clear();//OLED清屏 gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_1);//PA1配置成上拉输入 nvic_irq_enable(EXTI1_IRQn, 2U, 0U);//enable and set key EXTI interrupt to the lowest priority gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOA, GPIO_PIN_SOURCE_1);//connect key EXTI line to key GPIO pin exti_init(EXTI_1, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断 exti_interrupt_flag_clear(EXTI_1);//清中断标志 //PA2给ADC gpio_init(GPIOA, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_2);//PA2配置成上拉输入 nvic_irq_enable(EXTI2_IRQn, 2U, 0U);//enable and set key EXTI interrupt to the lowest priority gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOA, GPIO_PIN_SOURCE_2);//connect key EXTI line to key GPIO pin exti_init(EXTI_2, EXTI_INTERRUPT, EXTI_TRIG_FALLING);//下降沿中断 exti_interrupt_flag_clear(EXTI_2);//清中断标志 while (1) { if (gpio_input_bit_get(GPIOA, GPIO_PIN_2) == RESET && IntFlag == 0x55) //ADC显示电压 需要换个接口 { adc_flag_clear(ADC1,ADC_FLAG_EOC);//清ADC结束标志 while(SET != adc_flag_get(ADC1,ADC_FLAG_EOC)) {//判断是否结束 adc_value = ADC_RDATA(ADC1);//读取ADC寄存器值 Vol_Value=adc_value*3300/4095/1000;//寄存器值转换成电压值 //Vol_Value1=330; OLED_Clear();//OLED清屏 OLED_ShowNum(5,2,Vol_Value1,4,32); delay_1ms(1000); }//等待5秒 } if (gpio_input_bit_get(GPIOA, GPIO_PIN_1) == RESET && IntFlag == 0x55) //信息显示 { // 清除中断标志(重要,防止重复触发) IntFlag = 0; // 假设这是一个合适的清零操作 OLED_Clear(); gpio_bit_set(GPIOB, GPIO_PIN_4); // 根据currentLine的值显示相应的信息 if (currentLine < sizeof(chineseMessages) / sizeof(chineseMessages[0])) { OLED_ShowCHinese(chineseMessages[currentLine][0], 0, chineseMessages[currentLine][1]); } else if (currentLine >= sizeof(chineseMessages) / sizeof(chineseMessages[0]) && currentLine < sizeof(chineseMessages) / sizeof(chineseMessages[0]) + sizeof(englishMessages) / sizeof(englishMessages[0])) { if((currentLine - sizeof(chineseMessages) / sizeof(chineseMessages[0]))==0) { OLED_ShowCHinese(12,0,0);//显示中文(浙) OLED_ShowCHinese(30,0,1);//显示中文(江) OLED_ShowCHinese(48,0,2);//显示中文(力) OLED_ShowCHinese(66,0,3);//显示中文(控) OLED_ShowCHinese(84,0,4);//显示中文(科) OLED_ShowCHinese(102,0,5);//显示中文(技) OLED_ShowString(21, 3, englishMessages[currentLine - sizeof(chineseMessages) / sizeof(chineseMessages[0])]); } if((currentLine - sizeof(chineseMessages) / sizeof(chineseMessages[0]))==1) { OLED_ShowCHinese(12,0,0);//显示中文(浙) OLED_ShowCHinese(30,0,1);//显示中文(江) OLED_ShowCHinese(48,0,2);//显示中文(力) OLED_ShowCHinese(66,0,3);//显示中文(控) OLED_ShowCHinese(84,0,4);//显示中文(科) OLED_ShowCHinese(102,0,5);//显示中文(技) OLED_ShowString(21,3,(u8 *)"HUZHOU*ANJI");//显示字符 这里都是先列后行 OLED_ShowString(16, 6, englishMessages[currentLine - sizeof(chineseMessages) / sizeof(chineseMessages[0])]); } } delay_1ms(100); // 假设这里延迟1秒,以便观察显示结果 gpio_bit_reset(GPIOB, GPIO_PIN_4); // 更新currentLine以显示下一行(如果有的话) currentLine = (currentLine + 1) % (sizeof(chineseMessages) / sizeof(chineseMessages[0]) + sizeof(englishMessages) / sizeof(englishMessages[0])); } } } 4613浏览量 18回复量 关注量