大家好!
我用一颗STM8S003 的芯片连接一个串口的WIFI 模块, 我想使能STM8 串口接收中断。
具体做法如下:
1. 初始化 时钟和串口:
void main()
{
My_CLK_Config();
// 初始化时钟
disableInterrupts();
// 关闭中断
UART1_DeInit();
//复位UART1
UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_NO,UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
// 配置串口
UART1_ITConfig(UART1_IT_RXNE,ENABLE);
//配置串口1的接收中断
enableInterrupts();
// 开启中断
while (1)
{ }
}
2. 设置中断向量 表:
extern void _stext(); /* startup rou
tine */
extern @far @interrupt void UART1_RX_IRQHandler(void);
extern @far @interrupt void TIM2_UPD_OVF_BRK_IRQHandler(void);
extern @far @interrupt void EXTI_PORTD_IRQHandler(void);
extern @far @interrupt void EXTI_PORTC_IRQHandler(void);
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, (interrupt_handler_t)EXTI_PORTC_IRQHandler}, /* irq5 */
{0x82, (interrupt_handler_t)EXTI_PORTD_IRQHandler}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, (interrupt_handler_t)TIM2_UPD_OVF_BRK_IRQHandler}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, (interrupt_handler_t)UART1_RX_IRQHandler}, /* irq18 */
完成以上操作后, 我在main 文件中 串口中断 入口 打了断点: 但是电脑串口发送数据到STM8,断点没有停止。
请问以上设置有没有遗漏的?
@far @interrupt void UART1_RX_IRQHandler(void)
{
if(UART1->SR UART1_FLAG_RXNE)
{
rxbuf[rx_num++]=UART1_ReceiveData8();
UART1_SendData8(UART1_ReceiveData8());
}
}