嵌入式开发者社区

标题: 裸机UART中断问题 [打印本页]

作者: lsl    时间: 2019-8-2 11:19
标题: 裸机UART中断问题
初始化使能了发送空中断,但是程序一直进不去中断是什么问题?

#include "hw_types.h"
#include "soc_C665x.h"
#include "uart.h"
#include "interrupt.h"
#include "cic_event.h"
#include "Board.h"

#define UICIC_OUTNUM 0;
#define CIC0_SYSTEM_EVENT_UART0 164;

DSPType DSPChipType;// DSP 芯片型号
BoardUART uart0cfg;// 串口配置
unsigned int flag=0;
char txArray[]="Hello Word\n\r";

void Delay(volatile unsigned int n)
{
    unsigned int i;
    for(i = n; i > 0; i--);
}

void PeriphInit()
{
    // 串口初始化
    uart0cfg.ID = BoardUART0;
    uart0cfg.BaudRate = BAUD_115200;
    uart0cfg.config = UART_WORDL_8BITS;
    uart0cfg.OverSampRate = UART_OVER_SAMP_RATE_16;
    UARTInit(&uart0cfg);
    UARTIntEnable(SOC_UART_0_REGS,UART_INT_LINE_STAT|UART_INT_TX_EMPTY|UART_INT_RXDATA_CTI);
}

void UARTIsr();

void main(void)
{
    DSPChipType = DSPTypeGet();

    IntDSPINTCInit();
    IntGlobalEnable();

    CICDisableGlobalHostInt(SOC_CIC_0_REGS);
    CICEventMap(SOC_CIC_0_REGS,164,0);
    CICEnableGlobalHostInt(SOC_CIC_0_REGS);

    IntEventMap(C66X_MASK_INT4,SYS_INT_CIC0_OUT0_20);
    IntRegister(C66X_MASK_INT4,UARTIsr);
    IntEnable(C66X_MASK_INT4);

    PeriphInit();
    while(1);
}


void UARTIsr()
{
    static unsigned int length = sizeof(txArray);
    static unsigned int count = 0;
    unsigned int int_id = 0;
    unsigned char rxData=0;

    int_id = UARTIntStatus(SOC_UART_0_REGS);
    CICClearSystemEvent(SOC_CIC_0_REGS, 164);
    if(UART_INTID_TX_EMPTY == int_id)
    {
        if(0 < length)
        {
                // 写一个字节到 THR
           UARTCharPutNonBlocking(SOC_UART_0_REGS, txArray[count]);
           length--;
           count++;
        }
        if(0 == length)
        {
                // 禁用发送中断
           UARTIntDisable(SOC_UART_0_REGS, UART_INT_TX_EMPTY);
        }
    }

        // 接收中断
    if(UART_INTID_RX_DATA == int_id)
    {
            rxData= UARTCharGetNonBlocking(SOC_UART_0_REGS);

            UARTCharPutNonBlocking(SOC_UART_0_REGS, rxData);
    }

    // 接收错误
    if(UART_INTID_RX_LINE_STAT == int_id)
    {
        while(UARTRxErrorGet(SOC_UART_0_REGS))
        {
            // 从 RBR 读一个字节
            UARTCharGetNonBlocking(SOC_UART_0_REGS);
        }
    }
}



作者: lsl    时间: 2019-8-2 11:22
型号:TMS320C6678
作者: 风潇潇姿姣姣    时间: 2020-10-29 10:56
我也遇到了这样的问题,我的操作方案是重新使能,这样可以进入,但是如果发送数据的频率较高就会出错。
作者: lsl    时间: 2020-11-16 16:25
风潇潇姿姣姣 发表于 2020-10-29 10:56
我也遇到了这样的问题,我的操作方案是重新使能,这样可以进入,但是如果发送数据的频率较高就会出错。 ...

我出错的原因是初始化时的事件号写错了




欢迎光临 嵌入式开发者社区 (https://51dsp.net/) Powered by Discuz! X3.4