本人现在需要开发一个项目,串口接收波特率需要为921600,但是现在经过测试在接收超过100bytes长数据时会出现接收错误和不完全的情况,初始化代码如下,求大佬们帮帮忙解答一下
void sys_clock_init(void)
{
uint32_t val;
// 设置PLL和CPU-PLL的锁定延迟时间
write32(F1C100S_CCU_BASE + CCU_PLL_STABLE_TIME0, 0x1ff);
write32(F1C100S_CCU_BASE + CCU_PLL_STABLE_TIME1, 0x1ff);
// 先把CPU时钟源设置为24Mhz晶振
val = read32(F1C100S_CCU_BASE + CCU_CPU_CFG);
val &= ~(0x3 << 16);
val |= (0x1 << 16);
write32(F1C100S_CCU_BASE + CCU_CPU_CFG, val);
sdelay(100);
// 设置PLL_VIDEO(N=66,M=8)
write32(F1C100S_CCU_BASE + CCU_PLL_VIDEO_CTRL, 0x81004107);
sdelay(100);
// 设置PLL_PERIPH(N=25,M=1) to 600Mhz
// write32(F1C100S_CCU_BASE + CCU_PLL_PERIPH_CTRL, 0x80041800);
// 设置PLL_PERIPH(N=26,M=1) to 624Mhz
write32(F1C100S_CCU_BASE + CCU_PLL_PERIPH_CTRL, 0x80041900);
sdelay(100);
// 设置AHB/APB/HCLKC的工作频率
#define HCLKC_DIV (0) // HCLKC=CPUCLK/1
#define AHB_CLK_SRC_SEL (3) // AHB source is (PLL_PERIPH/AHB_PRE_DIV)
#define APB_CLK_RATIO (1) // APB_CLK=AHB_CLK/2=100Mhz 208/2=104Mhz
#define AHB_PRE_DIV (2) // AHB_source=600/3=200Mhz 624/3=208Mhz
#define AHB_CLK_DIV_RATIO (0) // AHB_CLK=AHB_source/1=200Mhz 208Mhz
write32(F1C100S_CCU_BASE + CCU_AHB_APB_CFG, (
(HCLKC_DIV << 16) |
(AHB_CLK_SRC_SEL << 12) |
(APB_CLK_RATIO << 8) |
(AHB_PRE_DIV << 6) |
(AHB_CLK_DIV_RATIO << 4)
));
sdelay(100);
// 开启DE的front-end和back-end的DCLK门?
val = read32(F1C100S_CCU_BASE + CCU_DRAM_CLK_GATE);
val |= (0x1 << 26) | (0x1 << 24);
write32(F1C100S_CCU_BASE + CCU_DRAM_CLK_GATE, val);
sdelay(100);
// 配置PLL_CPU的值
clock_set_pll_cpu(720000000);
// 把CPU时钟源设置为PLL_CPU
val = read32(F1C100S_CCU_BASE + CCU_CPU_CFG);
val &= ~(0x3 << 16);
val |= (0x2 << 16);
write32(F1C100S_CCU_BASE + CCU_CPU_CFG, val);
sdelay(100);
}
static void uart1_init(UART_MOD_TypeDef* module)
{
uint32_t addr,val;
/*初始化接控制板串口PA2、PA3*/
addr=PIO_REG_BASE+PA_OFFSET+CFG0_OFFSET;
val = read32(addr); //读PA寄存器值
val &= ~(0Xf<<((3&0x7)<<2)); //与0fff,清除PA3
val &= ~(0Xf<<((2&0x7)<<2)); //与f0ff,清除PA2
val |= ((5 & 0x7)<<((3 & 0x7)<<2)); //PA3位或0x5
val |= ((5 & 0x7)<<((2 & 0x7)<<2)); //PA2位或0x5 目前寄存器,55aa,aa未知
write32(addr,val);
/* 打开UART1时钟树 */
addr=0x01c20000+0x68;
val=read32(addr);
val |= 1<<21 ;
write32(addr,val);
/* 软件复位UART1 */
addr=0x01c20000+0x02d0;
val = read32(addr);
val |= 1<<21;
write32(addr,val);
/* Config uart1 to 921600-8-1-0 */
addr = 0x01c25400;
write32(addr + 0x04, 0x0);
write32(addr + 0x08, 0xf7);
write32(addr + 0x10, 0x0);
val = read32(addr + 0x0c);
val |= (1 << 7);
write32(addr + 0x0c, val); //选择波特率传感器
write32(addr + 0x00, 0x07 & 0xff); //低八位
write32(addr + 0x04, (0x07 >> 8) & 0xff); //高八位
val = read32(addr + 0x0c); //读传感器
val &= ~(1 << 7); //清零分频寄存器位
write32(addr + 0x0c, val); //锁位
val = read32(addr + 0x04); //锁位后读取中断标志位启动接收中断
val |= 0x01;
write32(addr + 0x04,val); //写入数据
val = read32(addr + 0x0c); //再次读串口寄存器
val &= ~0x1f; //只保留高三位,后五位清零
val |= (0x3 << 0) | (0 << 2) | (0x0 << 3);
write32(addr + 0x0c, val);
// 配置中断
f1c100s_intc_set_isr(F1C100S_IRQ_UART1, uart1_irq);
f1c100s_intc_enable_irq(F1C100S_IRQ_UART1);
}
离线