型号:STM8S103F3P6
时钟初始化:
void CLK_Configuration(void)
{
/* Configure clock prescaler */
CLK_CKDIVR = 0x08; /* To be programmed with different value */
/* Fmaster, Fmaster/2(8MHZ), fcup = fmaster */
/* To select external source by automtic switch */
CLK_PCKENR1 = 0x34;//enable Time4 and Time2 ,UART1 clock
CLK_PCKENR2 = 0x0C;//enable Adc and AWU clock
//CLK_SWCR |= 0x02; /* Enable switch */
// CLK_SWR = 0xB4; /* Select HSE */
//while(!(CLK_SWCR & 0x08));//等待切换完成
}
UART1初始化
void init_UART(void)
{
UART1_CR1 = 0x00; //8bit 无校验
UART1_CR3 = 0x00; // 1 停止位
UART1_BRR2 = 0x1b;//1200bit
UART1_BRR1 = 0xa0;
UART1_CR2 = 0xac;//允许发送和接收中断,使能发送和接收
}
现在问题是:
仿真的时候UART1寄存器永远初始化不了,都是0x00,除了UART1_SR = 0xc0
开发环境:STVP,C编译器:CXSTM8
现在项目很急,请各位仁兄,支支招,我已搞了一个通宵了
|