汇集网友智慧,解决技术难题
寄存器 定时器 定时 示波器 串口接收 hc32f460
赞0
评论
2024-06-30
2024-06-29
2024-06-28
2024-06-03
gouguoccc 发表于 2024-5-13 08:08 多半还是代码问题,贴上来大家看看。
static void Usart3RxIrqCallback(void) { read = USART_RecData(USART3_CH); if(RXflage == false) { RXbuff[readdata] = read; if((RXbuff[0] & 0xFF) == 0xAC) { readdata++; if(readdata >= 8) { readdata = 0; RXflage = true; } } } } static void Usart3TxIrqCallback(void) { if(TXflage == true) { USART_SendData(USART3_CH, TXbuff[writedata+1]); writedata++; if(writedata >= 7) { writedata = 0; TXflage = false; } } else if(TXflage == false) { //USART_FuncCmd(USART3_CH, UsartTxEmptyInt, Disable); //USART_FuncCmd(USART3_CH, UsartTxCmpltInt, Enable); while (Reset == USART_GetStatus(USART3_CH, UsartTxComplete)) { } EN_485_L; } } static void Usart3ErrIrqCallback(void) { if (Set == USART_GetStatus(USART3_CH, UsartFrameErr)) USART_ClearStatus(USART3_CH, UsartFrameErr); if (Set == USART_GetStatus(USART3_CH, UsartParityErr)) USART_ClearStatus(USART3_CH, UsartParityErr); if (Set == USART_GetStatus(USART3_CH, UsartOverrunErr)) USART_ClearStatus(USART3_CH, UsartOverrunErr); if (Set == USART_GetStatus(USART3_CH, UsartRxNoEmpty)) USART_ClearStatus(USART3_CH, UsartRxNoEmpty); if (Set == USART_GetStatus(USART3_CH, UsartTxComplete)) USART_ClearStatus(USART3_CH, UsartTxComplete); if (Set == USART_GetStatus(USART3_CH, UsartTxEmpty)) USART_ClearStatus(USART3_CH, UsartTxEmpty); if (Set == USART_GetStatus(USART3_CH, UsartRxTimeOut)) USART_ClearStatus(USART3_CH, UsartRxTimeOut); if (Set == USART_GetStatus(USART3_CH, UsartRxMpb)) USART_ClearStatus(USART3_CH, UsartRxMpb); } static void Usart3TimeoutIrqCallback(void) { TIMER0_Cmd(TMR_UNIT,Tim0_ChannelA,Disable); //USART3_CH->CR1_f.CRTOF = 1ul; USART_ClearStatus(USART3_CH, UsartRxTimeOut); } static void Usart3TxCmpltIrqCallback(void) { USART_FuncCmd(USART3_CH,UsartTx,Disable); USART_FuncCmd(USART3_CH,UsartTxCmpltInt,Disable); } void Uart3_Init(void) { en_result_t enRet = Ok; stc_irq_regi_conf_t stcIrqRegiCfg; const stc_usart_uart_init_t stcInitCfg = { UsartIntClkCkNoOutput, //UsartIntClkCkOutput, UsartClkDiv_64, UsartDataBits8, UsartDataLsbFirst, UsartOneStopBit, UsartParityNone, UsartSampleBit8, UsartStartBitFallEdge, UsartRtsEnable, }; PWC_Fcg1PeriphClockCmd(PWC_FCG1_PERIPH_USART3,Enable); PORT_SetFunc(USART3_RX_PORT,USART3_RX_PIN,USART3_RX_FUNC,Disable); PORT_SetFunc(USART3_TX_PORT,USART3_TX_PIN,USART3_TX_FUNC,Disable); enRet = USART_UART_Init(USART3_CH,&stcInitCfg); if(enRet != Ok) { while(1) { } } enRet = USART_SetBaudrate(USART3_CH,USART3_BAUDRATE); if(enRet != Ok) { while(1) { } } stcIrqRegiCfg.enIRQn = Int001_IRQn; stcIrqRegiCfg.pfnCallback = &Usart3RxIrqCallback; stcIrqRegiCfg.enIntSrc = USART3_RI_NUM; enIrqRegistration(&stcIrqRegiCfg); NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn); NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn); stcIrqRegiCfg.enIRQn = Int002_IRQn; stcIrqRegiCfg.pfnCallback = &Usart3ErrIrqCallback; stcIrqRegiCfg.enIntSrc = USART3_EI_NUM; enIrqRegistration(&stcIrqRegiCfg); NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn); NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn); stcIrqRegiCfg.enIRQn = Int008_IRQn; stcIrqRegiCfg.pfnCallback = &Usart3TimeoutIrqCallback; stcIrqRegiCfg.enIntSrc = USART3_RTO_NUM; enIrqRegistration(&stcIrqRegiCfg); NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn); NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn); stcIrqRegiCfg.enIRQn = Int000_IRQn; stcIrqRegiCfg.pfnCallback = &Usart3TxIrqCallback; stcIrqRegiCfg.enIntSrc = USART3_TI_NUM; enIrqRegistration(&stcIrqRegiCfg); NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn); NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn); stcIrqRegiCfg.enIRQn = Int004_IRQn; stcIrqRegiCfg.pfnCallback = &Usart3TxCmpltIrqCallback; stcIrqRegiCfg.enIntSrc = USART3_TCI_NUM; enIrqRegistration(&stcIrqRegiCfg); NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn); NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn); USART_FuncCmd(USART3_CH, UsartRx, Enable); USART_FuncCmd(USART3_CH, UsartRxInt, Enable); USART_FuncCmd(USART3_CH, UsartTx, Enable); USART_FuncCmd(USART3_CH, UsartTimeOut, Enable); USART_FuncCmd(USART3_CH, UsartTimeOutInt, Enable); USART_FuncCmd(USART3_CH, UsartTxEmptyInt, Enable); //USART_SetMode(USART3_CH, UsartUartMode); }
2024-05-28
yang377156216 发表于 2024-5-11 15:54 大概率是超时配置错误或者引脚功能配置不对了。
chenqianqian 发表于 2024-5-11 08:01 MCU和什么通信?你示波器量的是MCU引脚端的信号吗?
点击图片添加到编辑器内容中
点击文件名将附件添加到文章中
提交
tyw
315个答案
天意无罪
284个答案
xch
203个答案
jjjyufan
197个答案
coody
183个答案
LcwSwust
136个答案
chunyang
135个答案
呐咯密密
108个答案
赞0
评论
2024-06-30
赞0
评论
2024-06-29
赞0
评论
2024-06-28
赞0
评论
2024-06-28
赞0
评论
2024-06-28
赞0
评论
2024-06-03
赞0
评论
2024-05-28
赞0
但是我串口直接通讯可以,485就不行,有接收波形
评论
2024-05-28
赞0
两个mcu通讯,示波器量的是mcu引脚的信号
评论
2024-05-28
您需要登录后才可以回复 登录 | 注册