這個是創龍公司的例程,麻煩大佬幫忙看一下,怎么進入的發送中斷?開發手冊上講串口發送中斷有兩個條件,一是使能FIFO,二是發送保持暫存器空,我根據這個程式改的程式只能接收資料,都滿足觸發條件,但是不能主動發送資料。求指點以下
#include "TL138.h" // 創龍 TL138 開發板相關宣告
#include "hw_types.h" // 宏命令
#include "hw_syscfg0_OMAPL138.h" // 系統配置模塊暫存器
#include "soc_OMAPL138.h" // OMAPL138 外設暫存器
#include "psc.h" // 電源與睡眠控制宏及設備抽象層函式宣告
#include "gpio.h" // 通用輸入輸出口宏及設備抽象層函式宣告
#include "uart.h" // 通用異步串口宏及設備抽象層函式宣告
#include "interrupt.h" // OMAPL138 中斷相關應用程式介面函式宣告及系統事件號定義
/****************************************************************************/
/* */
/* 宏定義 */
/* */
/****************************************************************************/
// 時鐘
#define SYSCLK_1_FREQ (456000000)
#define SYSCLK_2_FREQ (SYSCLK_1_FREQ/2)
#define UART_2_FREQ (SYSCLK_2_FREQ)
/****************************************************************************/
/* */
/* 全域變數 */
/* */
/****************************************************************************/
char txArray[] = "Tronlong UART2 Application......\n\r";
/****************************************************************************/
/* */
/* 函式宣告 */
/* */
/****************************************************************************/
// 外設使能配置
void PSCInit(void);
// GPIO 管腳復用配置
void GPIOBankPinMuxSet();
// UART 初始化
void UARTInit(void);
// ARM 中斷初始化
void InterruptInit(void);
// UART 中斷初始化
void UARTInterruptInit();
// UART 中斷服務函式
void UARTIsr(void);
/****************************************************************************/
/* */
/* 主函式 */
/* */
/****************************************************************************/
int main(void)
{
// 外設使能配置
PSCInit();
// GPIO 管腳復用配置
GPIOBankPinMuxSet();
// ARM 中斷初始化
InterruptInit();
// UART 初始化
UARTInit();
// UART 中斷初始化
UARTInterruptInit();
// 主回圈
for(;;)
{
}
}
/****************************************************************************/
/* */
/* PSC 初始化 */
/* */
/****************************************************************************/
void PSCInit(void)
{
// 對相應外設模塊的使能也可以在 BootLoader 中完成
// 使能 UART2 模塊
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_UART2, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE);
}
/****************************************************************************/
/* */
/* GPIO 管腳復用配置 */
/* */
/****************************************************************************/
void GPIOBankPinMuxSet(void)
{
// UART2 禁用流控
UARTPinMuxSetup(2, FALSE);
}
/****************************************************************************/
/* */
/* ARM 中斷初始化 */
/* */
/****************************************************************************/
void InterruptInit(void)
{
// 初始化 ARM 中斷控制器
IntAINTCInit();
// 使能 IRQ(CPSR)
IntMasterIRQEnable();
// 使能中斷(AINTC GER)
IntGlobalEnable();
// 使能中斷(AINTC HIER)
IntIRQEnable();
}
/****************************************************************************/
/* */
/* UART 初始化 */
/* */
/****************************************************************************/
void UARTInit(void)
{
// 配置 UART2 引數
// 波特率 115200 資料位 8 停止位 1 無校驗位
UARTConfigSetExpClk(SOC_UART_2_REGS, UART_2_FREQ, BAUD_115200,
UART_WORDL_8BITS, UART_OVER_SAMP_RATE_16);
// 使能 UART2
UARTEnable(SOC_UART_2_REGS);
// 使能接收 / 發送 FIFO
UARTFIFOEnable(SOC_UART_2_REGS);
// 設定 FIFO 級別
UARTFIFOLevelSet(SOC_UART_2_REGS, UART_RX_TRIG_LEVEL_1);
}
/****************************************************************************/
/* */
/* UART 中斷初始化 */
/* */
/****************************************************************************/
void UARTInterruptInit(void)
{
IntRegister(SYS_INT_UARTINT2, UARTIsr);
IntChannelSet(SYS_INT_UARTINT2, 2);
IntSystemEnable(SYS_INT_UARTINT2);
// 使能中斷
unsigned int intFlags = 0;
intFlags |= (UART_INT_LINE_STAT | \
UART_INT_TX_EMPTY | \
UART_INT_RXDATA_CTI);
UARTIntEnable(SOC_UART_2_REGS, intFlags);
}
/****************************************************************************/
/* */
/* UART 中斷服務函式 */
/* */
/****************************************************************************/
void UARTIsr()
{
static unsigned int length = sizeof(txArray);
static unsigned int count = 0;
unsigned char rxData = 0;
unsigned int int_id = 0;
// 確定中斷源
int_id = UARTIntStatus(SOC_UART_2_REGS);
// 清除 UART2 系統中斷
IntSystemStatusClear(SYS_INT_UARTINT2);
// 發送中斷
if(UART_INTID_TX_EMPTY == int_id)
{
if(0 < length)
{
// 寫一個位元組到 THR
UARTCharPutNonBlocking(SOC_UART_2_REGS, txArray[count]);
length--;
count++;
}
if(0 == length)
{
// 禁用發送中斷
UARTIntDisable(SOC_UART_2_REGS, UART_INT_TX_EMPTY);
}
}
// 接收中斷
if(UART_INTID_RX_DATA == int_id)
{
rxData = UARTCharGetNonBlocking(SOC_UART_2_REGS);
UARTCharPutNonBlocking(SOC_UART_2_REGS, rxData);
}
// 接收錯誤
if(UART_INTID_RX_LINE_STAT == int_id)
{
while(UARTRxErrorGet(SOC_UART_2_REGS))
{
// 從 RBR 讀一個位元組
UARTCharGetNonBlocking(SOC_UART_2_REGS);
}
}
return;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/131681.html
標籤:其他硬件開發
上一篇:單片機做PPM調制
下一篇:CCS錯誤提示怎么解決
