目前正在用STM8L152C8单片调试设备,串口2可以进入发送中断,但是进不去接收中断。各位大神帮帮忙。。。
void INIT_USART2()
{
PE_DDR_DDR4 = 1; //PE4输出口 TXD1
PE_CR1_C14 = 1; //上拉输出
PE_DDR_DDR3 = 0; //PE3输入口 RXD1
PE_CR1_C13 = 1; //上拉输入
USART2_CR3_CLKEN = 1; //USART_CK pin enabled
USART2_BRR1 = 0x68; //波特率2400 P-515 主时钟16M/4 0x34 0x01
USART2_BRR2 = 0x03;
USART2_CR1_M = 0; //1 Start bit, 8 Data bits, ‘n’ STOP bit
USART2_CR3_STOP = 0; //1位停止位
USART2_CR1_PCEN = 1; //校验使能
USART2_CR1_PS = 0; //偶校验
USART2_CR2_RIEN = 1; //接收中断使能
USART2_CR2_TEN = 1; //发送使能
USART2_CR2_REN = 1; //接收使能
}
void SYS_CLK()
{
CLK_CKDIVR_CKM = 2; //系统时钟4分频 16M/4 = 4M
CLK_ICKCR_HSION = 1;//打开内部高速时钟HSI
while(!CLK_ICKCR_HSIRDY);//HSI时钟准备完成
CLK_PCKENR1_PCKEN14 = 1;//SPI时钟使能
CLK_PCKENR1_PCKEN15 = 1;//UASRT1时钟使能
CLK_PCKENR2_PCKEN20 = 1;//ADC1时钟使能
CLK_PCKENR2_PCKEN22 = 1;//RTC时钟使能
CLK_PCKENR3_PCKEN33 = 1;//UASRT2时钟使能
CLK_PCKENR3_PCKEN34 = 1;//UASRT3时钟使能
CLK_PCKENR2_PCKEN21 = 1;//TIM1时钟使能
CLK_PCKENR1_PCKEN10 = 1;//TIM2时钟使能
CLK_ECKCR_LSEON = 1; //外部低速时钟打开
while(!CLK_ECKCR_LSERDY);//等待外部低速时钟稳定
}
void main( void )
{
PORT_INIT();
SYS_CLK();
INIT_data();
INIT_USART2();
__enable_interrupt();//打开全局中断
while(1)
{
delay(10000);
}
}
#pragma vector=USART2_R_RXNE_vector //USART2 接收中断
__interrupt void USART2_receive()
{
RX_buf[0] = USART2_DR;
}
此帖出自
小平头技术问答
一周热门 更多>