-
HC32L17系列串口通信问题 sos
案例代码都是用9600作为波特率与串口通信,结果没问题,但是调到115200后,出现了乱码,发现是实际波特率的问题,于是用示例的App_RCH4MHzToPll48MHz代码,调到48MHZ,实际串口没问题,但是在与4G模块通信时,还是会出现数据缺失的问题 [img]data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAA5CAIAAABVrPmkAAADzElEQVR4Ae2b304UMRTG2+EhCL6T+iQ+A2IiJhhUWFB2V99IvBFv8AITRVxEVEBv1wyHfPvtaedfZ2eFUkLI1zPntD2//pkys2vs4Nz2z2z/t935ZV+d2pc/7PZ32xvZzSO7cWiff7brB3Zt3zx+bx7uLt19sLi4OB6PTfppA255bORXMHKR7XFCDga3TNMO2hVxUjPGdAEO+KKlZozJhhfZ4DwbnJXvcXZ1z668W7o32eOYDnT8KxRzYebgjMk3vvh/ugB3K9glcIGLIxicTCve1G7XcaQNuMCxiiMsgQscxwQuEJwdXuRn4IH8u/oz/3d1+8RuHdveN7v51b74YtYPzNq+Wd0zK2/5HBfYXjRhLcHxkQ03B75juKDYje8wqIodxIgKcYkD3SbmYZktOJzgQEFyQBECnl7BRm8N3nrmwQtttAfHObgJe9NG6yVX3WrFwn9VuKq222IbcG4OLjgsLgg3H++lcnCoRLnB3rnoGpwkgPQgOLE6RvERxIj1BuJqt6IlOHeyeJOBEYKzqmMUn3jASf6cOWumU+LpDVFGFCHcyudqqZxx9tkn+/SjffJBneN48KHdCegmo3xUUXZJGAUTimoP/Z8Qg8G5RG6XJYELHO8ELoELJBAYNtsZh11cberYxdmBffieUCcTrkf82YLm3JuJarROW36f9uDQSwjuLowQfBU5K+Hv67QVFZaIorYQMl1lk1JH4NAFdBHCm4xcLfFBhRBwVgJF8ZSZqKKUD642EPXB2Ue76nmcWh3e3sCH+6Q8kZuyc4ir3Zq9FjVO0kSjhtymc0sbcFIjOgHBLdUxig/wcXiJRhR86lgUR8Q2FjcdHINwBwlzkC+xbswLAe3BoSruEDQE3DhVMcIHgp2LNJwbCbf1ovor7DMEJ33iFYcBRydggRssKiXgQCwLFYUiBDojUWKHsbxybqhQzxZcYTPxXUjgAsc0gQsEt/Dmb/5Oenh++THgq/eqWf4x4Kv3qnge557jApuMI8wLjl9IJ3D+gU7g/FwqrdnrP+5STTOukptJ4KoZeT3SUvViqTYmcNWMvB4JnBdLtRF73OVXHeQcd2q3Tha2j7PeUbZxyMeRO/cn33Oorjpuj0bg1IPMuMlUZOcDl38i0zvjErgJzSJw2dbIXaoJXAI3IRCoimZcnaXKTw3VM0I8OAzs1vUPCwbHD1GhXXH9CQT2sAtwwBfYpxsRxuCy/uXX8qe/58DnOL45MB3o+FcoBtULzvRGlQ8yAYtfsoiRL6Gh2EQX4BhlbLyQTwIHFM1EMDh1/lDF6De7f28tAO9q96A8AAAAAElFTkSuQmCC[/img] 发送AT+CPIN?后,应该回复+CPIN:READY,但实际转发到串口查看,缺少数据D,实际代码也没往下跑,因为接收数据缺失 在检测4G模块正常的情况下,是哪里出现了问题?代码如下: /*author ljx*/ #include "hc32l17x.h" #include "uart.h" #include "gpio.h" int RxCount=0;//接收缓冲区坐标 char RxBuffer[1000];//接收缓冲区 //串口引脚配置 void usart1_Init(void) { stc_gpio_cfg_t stcGpioCfg; stc_uart_cfg_t stcCfg; stc_uart_baud_t stcBaud; DDL_ZERO_STRUCT(stcGpioCfg); DDL_ZERO_STRUCT(stcCfg); DDL_ZERO_STRUCT(stcBaud); Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); //使能GPIO模块时钟 ///
=1000) RxCount=0; //字符数组满了,从头再来 } } 473浏览量 0回复量 关注量 -
求助STC8H4K64TL单片机无法输出PWM4P_4, 详情如下 sos
void main() { P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; PWMA_CCER1 = 0x00; //写CCMRx前必须先清零CCERx关闭通道 PWMA_CCMR1 = 0x60; //设置CC1为PWMA输出模式 PWMA_CCER1 = 0x01; //使能CC1通道 PWMA_CCR4 = 100; //设置占空比时间 PWMA_ARR = 200; //设置周期时间 PWMA_ENO = 0x40; //使能PWM4P端口输出 PWMA_PS = 0XC0; PWMA_BKR = 0x80; //使能主输出 PWMA_CR1 = 0x01; //开始计时 while (1); } 搜索 [align=left]复制[/align] 下载视频
624浏览量 0回复量 关注量 -
代码移植问题 sos
从 STC8A8K64SA12移植PWM代码到到 STC8A8K64D4 ,不工作,看手册上也没说有啥不同啊,为何不工作?,还有,STC8A8K64D4的官网代码好啰嗦啊,完全仿照STM32的风格,简单的事情复杂化了,这是不是就是以后的趋势了... 下载视频
3546浏览量 0回复量 关注量 -
为什么计算的结果不对
用的是STC8A8K64D,定义了一个u16的变量,计算后通过串口发送。 u16 tmp; tmp = (2000-1000)*2999/1000; 为什么串口发送 tmp 为 0xFFF1。 将 tmp 定义为 u32。 u32 tmp; tmp = (2000-1000)*2999/1000; 串口发送数据为 0xFFFFFFF1。 再将 tmp 直接赋值为2999000,tmp = 2999000,串口输出数据为 0x2DC2D8(2999000)。 这是什么原因嘞?
4167浏览量 2回复量 关注量 -
STC的单片机,使用TYPE C转串口下载
STC的单片机,使用TYPE C转串口下载,TYPE C口上的CC1和CC2 我看资料上说要接5.1K电阻到低,不接可以吗?悬空 下载视频
5309浏览量 3回复量 关注量 -
STC8A8K64D4 无法手动复位
使用手动复位,按照说明中低电位有效,一个按键串了一个100欧的电阻到地,控制P5.4,并且在下载的时候√掉了将P5.4作为IO口,但是,不管怎么操作,就是不复位啊!还有,冷启动下载的时候,电源开关断开有时候CH340会断开,不能下载程序,反复几次才好。。。这个芯片好像用的人不多啊。。。盼高手指点迷津哦 下载视频
1324浏览量 5回复量 关注量 -
stc的bug吗? sos
如下的程序,工作大约10分钟,if就判断为真,就进入了, eerom.save_data.Blowback_cycle=6; Blowback_hour=0; TCON_bit.TR0 = 0; //停止定时器计时,防止改变小时变量影响if比较 if(eerom.save_data.Blowback_cycle==Blowback_hour) { Blowback_hour = 0; OLED_Clear(); OLED_ShowCHinese(0,0,30); OLED_ShowCHinese(16,0,31); /* i = sprintf(string,"fixed time"); OLED_ShowString(32,0,string); */ i = sprintf(string,"hout:%d",(int)Blowback_hour); OLED_ShowString(32,0,string); i = sprintf(string,"fixed time:%d",(int)eerom.save_data.Blowback_cycle); OLED_ShowString(0,2,string); Blowback(); OLED_Clear(); } if(zero_seting_hour>=eerom.save_data.zero_seting_cycle) { zero_seting_hour = 0; OLED_Clear(); OLED_ShowCHinese(0,0,12); OLED_ShowCHinese(16,0,35); i = sprintf(string,"fixed time"); OLED_ShowString(32,0,string); zero_setting(); OLED_Clear(); } TCON_bit.TR0 = 1; 后来改成 PSW_bit.CY = 0; if(PSW_bit.CY==0) { TCON_bit.TR0 = 0; //停止定时器计时,防止改变小时变量影响if比较 if(eerom.save_data.Blowback_cycle==Blowback_hour) { Blowback_hour = 0; OLED_Clear(); OLED_ShowCHinese(0,0,30); OLED_ShowCHinese(16,0,31); /* i = sprintf(string,"fixed time"); OLED_ShowString(32,0,string); */ i = sprintf(string,"hout:%d",(int)Blowback_hour); OLED_ShowString(32,0,string); i = sprintf(string,"fixed time:%d",(int)eerom.save_data.Blowback_cycle); OLED_ShowString(0,2,string); Blowback(); OLED_Clear(); } if(zero_seting_hour>=eerom.save_data.zero_seting_cycle) { zero_seting_hour = 0; OLED_Clear(); OLED_ShowCHinese(0,0,12); OLED_ShowCHinese(16,0,35); i = sprintf(string,"fixed time"); OLED_ShowString(32,0,string); zero_setting(); OLED_Clear(); } TCON_bit.TR0 = 1; } 这样就解决了,
1338浏览量 0回复量 关注量 -
请问STC8H8K64U逐飞科技例程的串口发送的和收到的为什么不同
[i=s] 本帖最后由 学电子的小峰源 于 2022-1-20 11:57 编辑 [/i] 官方例程函数内容肯定是没有写错的,但是为什么发送0x1E我收到的却是80?怎么才能收到正确的数值呢? 主函数: [img]http://uphotos.**/1642649509/pics/1642650142527090.png[/img]void main() { DisableGlobalIRQ(); //¹Ø±Õ×ÜÖÐ¶Ï board_init(); //uart_init(DEBUG_UART,DEBUG_UART_BAUD,DEBUG_UART_RX_TX_PIN); //UART1ÒÑÔÚboard_init Öгõʼ»¯£¬²¨ÌØÂÊ115200 EnableGlobalIRQ(); //¿ªÆô×ÜÖÐ¶Ï while(1) { uart_putchar(DEBUG_UART,0x1E); delay_ms(100); } } 串口发送数据的函数 [img]http://uphotos.**/1642649509/pics/1642650186348277.png[/img] [img]http://uphotos.**/1642649509/pics/1642650201305291.png[/img] //------------------------------------------------------------------------------------------------------------------- // [url=home.php?mod=space&uid=247401]@brief[/url] ´串口字节输出 // @param uart_n 串口模块号(USART_1,USART_2,USART_3,USART_4) // @param dat 需要发送的字节 // [url=home.php?mod=space&uid=266161]@return[/url] void // Sample usage: uart_putchar(UART_1,0xA5); //串口1发送0xA5 //------------------------------------------------------------------------------------------------------------------- void uart_putchar(UARTN_enum uart_n,uint8 dat) { switch(uart_n) { case UART_1: while (busy[1]); busy[1] = 1; SBUF = dat; break; case UART_2: while (busy[2]); busy[2] = 1; S2BUF = dat; break; case UART_3: while (busy[3]); busy[3] = 1; S3BUF = dat; break; case UART_4: while (busy[4]); busy[4] = 1; S4BUF = dat; break; } } 宏定义 #define DEBUG_UART UART_1 #define DEBUG_UART_BAUD 115200 #define DEBUG_UART_RX_PIN UART1_RX_P30 #define DEBUG_UART_TX_PIN UART1_TX_P31 #define DEBUG_UART_TIM TIM_2 [img]http://uphotos.**/1642649509/pics/1642650230742208.png[/img] 串口界面如图 [img]http://uphotos.**/1642649509/pics/1642650247141560.png[/img]
1689浏览量 1回复量 关注量 -
HC32F460 的PH2这个脚配置成外部双沿中断 sos
void PortH_Init() { stc_exint_config_t stcExtiConfig; stc_irq_regi_conf_t stcIrqRegiConf; stc_port_init_t stcPortInit; /* configuration structure initialization */ MEM_ZERO_STRUCT(stcExtiConfig); MEM_ZERO_STRUCT(stcIrqRegiConf); MEM_ZERO_STRUCT(stcPortInit); /**************************************************************************/ /* External Int Ch.2 */ /**************************************************************************/ stcExtiConfig.enExitCh = ExtiCh02; /* Filter setting */ stcExtiConfig.enFilterEn = Enable; stcExtiConfig.enFltClk = Pclk3Div64; stcExtiConfig.enExtiLvl = ExIntBothEdge; EXINT_Init(&stcExtiConfig); /* Set External Int */ MEM_ZERO_STRUCT(stcPortInit); stcPortInit.enPullUp = Enable; stcPortInit.enExInt = Enable; PORT_Init(PortH,Pin02, &stcPortInit); /* Select External Int Ch.2 */ stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ2; /* Register External Int to Vect.No.000 */ stcIrqRegiConf.enIRQn = Int015_IRQn; /* Callback function */ stcIrqRegiConf.pfnCallback = &PORTH_PIN2_Callback; /* Registration IRQ */ enIrqRegistration(&stcIrqRegiConf); /* Clear pending */ NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn); /* Set priority */ NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT); /* Enable NVIC */ NVIC_EnableIRQ(stcIrqRegiConf.enIRQn); } void PORTH_PIN2_Callback() { if (Set == EXINT_Irq**Get(ExtiCh02)) { EXINT_Irq**Clr(ExtiCh02); } } 中断号没有被其他中断用到,这样配置后,会一直进放回调函数,不知会什么? 搜索 [align=left]复制[/align]
1462浏览量 0回复量 关注量 -
关于HC32L196串口奇偶校验问题
在配置HC32L196的串口0时,使用了mode 3, 下载视频 关于配置奇偶校验的地方不是很理解, stcCfg.enRunMode = UartMskMode3; ///<模式3 stcCfg.enStopBit = UartMsk1bit; ///<1bit停止位 stcCfg.enMmdorCk = UartMskDataOrAddr; ///< stcCfg.stcBaud.u32Baud = 115200; ///<波特率115200 stcCfg.stcBaud.enClkDiv = UartMsk8Or16Div; ///<通道采样分频配置 stcCfg.stcBaud.u32Pclk = Sysctrl_GetPClkFreq(); ///<获得外设时钟(PCLK)频率值 Uart_Init(M0P_UART0, &stcCfg); ///<串口初始化 UartMskDataOrAddr = 0u, ///<多机模式时,通过读写SBUF[8]决定帧为数据帧或地址帧 UartMskEven = 0x4u, ///<非多机模式偶校验 UartMskOdd = 0x8u, ///<非多机模式奇校验 这三个值,下面两个好理解,奇校验和偶校验, 但是第一个,它是无奇偶校验的意思么? 当我配置为 UartMskDataOrAddr 时 与电脑上的串口调试软件无法正常通讯 有没有人知道这个 UartMskDataOrAddr 是啥意思?
8986浏览量 3回复量 关注量 -
关于华大HC32F460的时钟配置问题
我在配置HC32F460的时钟,遇到了一个比较鬼畜的问题。我按照如下代码设置了时钟,但奇怪的是,我在硬件上端接晶振引脚,按说芯片会宕机才对,但芯片居然毫无影响,继续运行。想麻烦大家帮我看看,是我哪里设置的不对 [color=#d4d4d4][backcolor=rgb(30, 30, 30)][font=Menlo, Monaco, "][size=12px] [color=#569cd6]void[/color] [color=#dcdcaa]SystemClk_Init[/color]([color=#569cd6]void[/color]) { [color=#4ec9b0]stc_clk_sysclk_cfg_t[/color] [color=#9cdcfe]stcSysClkCfg[/color]; [color=#4ec9b0]stc_clk_xtal_cfg_t[/color] [color=#9cdcfe]stcXtalCfg[/color]; [color=#4ec9b0]stc_clk_mpll_cfg_t[/color] [color=#9cdcfe]stcMpllCfg[/color]; [color=#569cd6]MEM_ZERO_STRUCT[/color]([color=#9cdcfe]stcSysClkCfg[/color]); [color=#569cd6]MEM_ZERO_STRUCT[/color]([color=#9cdcfe]stcXtalCfg[/color]); [color=#569cd6]MEM_ZERO_STRUCT[/color]([color=#9cdcfe]stcMpllCfg[/color]); [color=#6a9955]/* Set bus clk div. */[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enHclkDiv[/color] = [color=#4fc1ff]ClkSysclkDiv1[/color]; [color=#6a9955]// 168MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enExclkDiv[/color] = [color=#4fc1ff]ClkSysclkDiv2[/color]; [color=#6a9955]// 84MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enPclk0Div[/color] = [color=#4fc1ff]ClkSysclkDiv1[/color]; [color=#6a9955]// 168MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enPclk1Div[/color] = [color=#4fc1ff]ClkSysclkDiv2[/color]; [color=#6a9955]// 84MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enPclk2Div[/color] = [color=#4fc1ff]ClkSysclkDiv4[/color]; [color=#6a9955]// 42MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enPclk3Div[/color] = [color=#4fc1ff]ClkSysclkDiv4[/color]; [color=#6a9955]// 42MHz[/color] [color=#9cdcfe]stcSysClkCfg[/color].[color=#9cdcfe]enPclk4Div[/color] = [color=#4fc1ff]ClkSysclkDiv2[/color]; [color=#6a9955]// 84MHz[/color] [color=#dcdcaa]CLK_SysClkConfig[/color](&[color=#9cdcfe]stcSysClkCfg[/color]); [color=#6a9955]/* Switch system clock source to MPLL. */[/color] [color=#6a9955]/* Use Xtal as MPLL source. */[/color] [color=#9cdcfe]stcXtalCfg[/color].[color=#9cdcfe]enMode[/color] = [color=#4fc1ff]ClkXtalModeOsc[/color]; [color=#9cdcfe]stcXtalCfg[/color].[color=#9cdcfe]enDrv[/color] = [color=#4fc1ff]ClkXtalLowDrv[/color]; [color=#9cdcfe]stcXtalCfg[/color].[color=#9cdcfe]enFastStartup[/color] = [color=#4fc1ff]Disable[/color]; [color=#dcdcaa]CLK_XtalConfig[/color](&[color=#9cdcfe]stcXtalCfg[/color]); [color=#dcdcaa]CLK_XtalCmd[/color]([color=#4fc1ff]Enable[/color]); [color=#6a9955]/* MPLL config. */[/color] [color=#9cdcfe]stcMpllCfg[/color].[color=#9cdcfe]pllmDiv[/color] = [color=#b5cea8]1u[/color]; [color=#9cdcfe]stcMpllCfg[/color].[color=#9cdcfe]plln[/color] = [color=#b5cea8]42u[/color]; [color=#9cdcfe]stcMpllCfg[/color].[color=#9cdcfe]PllpDiv[/color] = [color=#b5cea8]2u[/color]; [color=#9cdcfe]stcMpllCfg[/color].[color=#9cdcfe]PllqDiv[/color] = [color=#b5cea8]2u[/color]; [color=#9cdcfe]stcMpllCfg[/color].[color=#9cdcfe]PllrDiv[/color] = [color=#b5cea8]2u[/color]; [color=#dcdcaa]CLK_SetPllSource[/color]([color=#4fc1ff]ClkPllSrcXTAL[/color]); [color=#dcdcaa]CLK_MpllConfig[/color](&[color=#9cdcfe]stcMpllCfg[/color]); [color=#6a9955]/* flash read wait cycle setting */[/color] [color=#dcdcaa]EFM_Unlock[/color](); [color=#dcdcaa]EFM_SetLatency[/color]([color=#569cd6]EFM_LATENCY_4[/color]); [color=#dcdcaa]EFM_Lock[/color](); [color=#6a9955]/* Enable MPLL. */[/color] [color=#dcdcaa]CLK_MpllCmd[/color]([color=#4fc1ff]Enable[/color]); [color=#6a9955]/* Wait MPLL ready. */[/color] [color=#c586c0]while[/color] ([color=#4fc1ff]Set[/color] != [color=#dcdcaa]CLK_GetFlagStatus[/color]([color=#4fc1ff]ClkFlagMPLLRdy[/color])) { } [color=#6a9955]/* Switch system clock source to MPLL. */[/color] [color=#dcdcaa]CLK_SetSysClkSource[/color]([color=#4fc1ff]ClkSysSrcXTAL[/color]); } [/size][/font][/backcolor][/color]
6007浏览量 9回复量 关注量 -
想通过初始化GPIO口采集外部电平信号但总是初始化不成功。 sos
[size=14px] Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE); //timer [/size] [size=14px] stc_gpio_cfg_t stcGpioCfg; [/size] [size=14px] stcGpioCfg.enDir = GpioDirIn; [/size] [size=14px] stcGpioCfg.enPu = GpioPuEnable;[/size] [size=14px] stcGpioCfg.enCtrlMode = GpioAHB;[/size] [size=14px] Gpio_Init(GpioPortB, GpioPin6,&stcGpioCfg); [/size] [size=14px] [/size] [size=14px] [/size] [size=14px] while (1) {[/size] [size=14px] [/size] [size=14px] rev_len = DevUART_Read(&gDebugUart, recv_buf, MEM_POOL_BLOCK_SIZE, OS_ALWAYS_DELAY); [/size] [size=14px] uint8_t dian;[/size] [size=14px] //unsigned char *G;[/size] [size=14px] uint8_t *G;[/size] [size=14px] dian=Gpio_GetInputIO(GpioPortB,GpioPin6);[/size] [size=14px] sprintf(G,"%d",dian); [/size] [size=14px] AT_TxFreq(0, G, rev_len);[/size] [size=14px] gEnableRadioRx = true;[/size] [size=14px] osDelayMs(10); [/size]
1532浏览量 0回复量 关注量 -
有个疑问,为什么8位单片机的频率不能搞到70M,100MHZ?
既然32位能上那么高的频率,按理8位应该也行啊,如果8位单片机把频率提高到M4一样的200MHZ上去,岂不是美滋滋?难道是指令集限制了频率的提升?那X86也是复杂指令集啊人家能上到几GHZ怎么说应该弄到上百MHZ不难啊,如果STC单片机搞到200MHZ,那不是可以解决很多问题了而且大家又都能上手没什么学习成本
4914浏览量 36回复量 关注量 -
STC的单片机下载程序还那么麻烦吗?能在线调试吗?
记得上学时候,给STC单片机下载程序,需要断电再上电,真麻烦!现在怎么样了?另外,STC单片机有像Jlink那样的在线调试工具吗?
1903浏览量 15回复量 关注量