| 
 | 
 
我现在用的开发板是c6748EVM A3,我在跑RS485例程的时候,可以直接输出程序中储存的字符串,但是当我从PC发送数据时,只有在调试状态单步进行并且只发送单个字符的时候串口终端才会有回显。另外我将485为改写为UART1中断触发,在中断服务函数设断点单步调试的时候可以进入中断,并打出一个字符,不设断点的话,无输出。程序用UART1的232串口是没有问题的,485就不行了,下面给程序。 
/****************************************************************************/ 
/*                                                                          */ 
/*              广州创龙电子科技有限公司                                    */ 
/*                                                                          */ 
/*              Copyright 2014 Tronlong All rights reserved                 */ 
/*              RS485 串口测试                                              */ 
/*              2014年07月12日                                              */ 
/****************************************************************************/ 
#include "TL6748.h"                 // 创龙 DSP6748 开发板相关声明 
#include "hw_types.h"               // 宏命令 
#include "hw_syscfg0_C6748.h"       // 系统配置模块寄存器 
#include "soc_C6748.h"              // DSP C6748 外设寄存器 
#include "psc.h"                    // 电源与睡眠控制宏及设备抽象层函数声明 
#include "gpio.h"                   // 通用输入输出口宏及设备抽象层函数声明 
#include "uart.h"                   // 通用异步串口宏及设备抽象层函数声明 
#include "uartStdio.h"              // 串口标准输入输出终端函数声明 
#include "interrupt.h"              // DSP C6748 中断相关应用程序接口函数声明及系统事件号定义 
#include <stdio.h> 
/*              宏定义                                                      */ 
// 时钟 
#define SYSCLK_1_FREQ     (456000000) 
#define SYSCLK_2_FREQ     (SYSCLK_1_FREQ/2) 
#define UART_1_FREQ       (SYSCLK_2_FREQ) 
 
/*              全局变量                                                    */ 
 
char txArray[] = "Tronglong RS485 Testing ......\n\r"; 
// 发送缓存 
char Send[] = "Tronglong RS485 Testing ......\n\r"; 
// 接收缓存 
unsigned char Receive; 
 
/****************************************************************************/ 
/*                                                                          */ 
/*              延时函数                                                    */ 
/*                                                                          */ 
/****************************************************************************/ 
static void Delay (int length) 
{ 
        while (length > 0) 
                length--; 
} 
 
/****************************************************************************/ 
/*                                                                          */ 
/*              PSC 初始化                                                  */ 
/*                                                                          */ 
/****************************************************************************/ 
void PSCInit(void) 
{ 
        // 使能 GPIO 模块 
        // 对相应外设模块的使能也可以在 BootLoader 中完成 
    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE); 
    // 使能 UART1 模块 
    PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_UART1, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE); 
} 
 
/****************************************************************************/ 
/*                                                                          */ 
/*              GPIO 管脚复用配置                                           */ 
/*                                                                          */ 
/****************************************************************************/ 
void GPIOBankPinMuxSet(void) 
{ 
        // 使能 UART1 禁用流控 
        UARTPinMuxSetup(1, FALSE); 
        // RS485 Enable 管脚 
        RS485PinMuxSetup(); 
} 
 
/****************************************************************************/ 
/*                                                                          */ 
/*              UART 初始化                                                 */ 
/*                                                                          */ 
/****************************************************************************/ 
void UARTInit(void) 
{ 
        // 配置 UART1 参数 
        // 波特率 115200 数据位 8 停止位 1 无校验位 
    UARTConfigSetExpClk(SOC_UART_1_REGS, UART_1_FREQ, BAUD_115200, UART_WORDL_8BITS, UART_OVER_SAMP_RATE_16); 
        // 使能 UART1 
        UARTEnable(SOC_UART_1_REGS); 
    // 使能接收 / 发送 FIFO 
    UARTFIFOEnable(SOC_UART_1_REGS); 
    // 设置 FIFO 级别 
    UARTFIFOLevelSet(SOC_UART_1_REGS, UART_RX_TRIG_LEVEL_1); 
        // 设置使能管脚为输出状态 GPIO0[11] 
        GPIODirModeSet(SOC_GPIO_0_REGS, 12, GPIO_DIR_OUTPUT); 
} 
/****************************************************************************/ 
/*                                                                          */ 
/*              UART 中断服务函数                                           */ 
/*                                                                          */ 
/****************************************************************************/ 
unsigned char rxData = 0; 
static void UARTIsr() 
{ 
        static char RS485Send[] = "\r\n============Test Start===========.\r\nUnderwater communicate by DPSK.\r\n"; 
        static unsigned int length = sizeof(RS485Send); 
    static unsigned int count = 0; 
 
    unsigned int int_id = 0; 
 
    // 确定中断源 
    int_id = UARTIntStatus(SOC_UART_1_REGS); 
 
    // 清除 UART2 系统中断 
    IntEventClear(SYS_INT_UART1_INT); 
 
    // 发送中断 
    if(int_id == UART_INTID_TX_EMPTY) 
    { 
        if(length > 0) 
        { 
            // 写一个字节到 THR 
            UARTCharPutNonBlocking(SOC_UART_1_REGS, RS485Send[count]); 
            length--; 
            count++; 
        } 
        if(length == 0) 
        { 
            // 禁用发送中断 
            UARTIntDisable(SOC_UART_1_REGS, UART_INT_TX_EMPTY); 
        } 
     } 
 
    // 接收中断 
    if(int_id == UART_INTID_RX_DATA) 
    { 
            rxData=UARTCharGetNonBlocking(SOC_UART_1_REGS); 
                   // 使能发送 
                   GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_HIGH); 
                   Delay(200); 
                   UARTCharPutNonBlocking(SOC_UART_1_REGS, rxData); 
                   // 关闭发送,使能接收 
                   GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_LOW); 
    } 
 
    // 接收错误 
    if(int_id == UART_INTID_RX_LINE_STAT) 
    { 
        while(UARTRxErrorGet(SOC_UART_1_REGS)) 
        { 
            // 从 RBR 读一个字节 
            UARTCharGetNonBlocking(SOC_UART_1_REGS); 
        } 
    } 
    return; 
} 
/****************************************************************************/ 
/*                                                                          */ 
/*              UART2 中断初始化                                             */ 
/*                                                                          */ 
/****************************************************************************/ 
static void UARTInterruptInit(void) 
{ 
        // 注册中断函数 
        IntRegister(C674X_MASK_INT5, UARTIsr); 
        // UART2中断映射 
        IntEventMap(C674X_MASK_INT5, SYS_INT_UART1_INT); 
        // 使能可屏蔽中断5 
        IntEnable(C674X_MASK_INT5); 
 
        // 使能中断 
        unsigned int intFlags = 0; 
    intFlags |= (UART_INT_LINE_STAT  | UART_INT_RXDATA_CTI); 
//                 UART_INT_TX_EMPTY | 
 
    UARTIntEnable(SOC_UART_1_REGS, intFlags); 
} 
/****************************************************************************/ 
/*                                                                          */ 
/*              DSP 中断初始化                                              */ 
/*                                                                          */ 
/****************************************************************************/ 
void InterruptInit(void) 
{ 
        // 初始化 DSP 中断控制器 
        IntDSPINTCInit(); 
 
        // 使能 DSP 全局中断 
        IntGlobalEnable(); 
} 
/****************************************************************************/ 
/*                                                                          */ 
/*              主函数                                                      */ 
/*                                                                          */ 
/****************************************************************************/ 
//F:\CRAB\RecentWork\DSP\demo\StarterWare\Application\RS485\Debug\RS485.ais 
 
int main(void) 
{ 
        // 外设使能配置 
        PSCInit(); 
        // GPIO 管脚复用配置 
        GPIOBankPinMuxSet(); 
        // DSP 中断初始化 
        InterruptInit(); 
        // UART 初始化 
        UARTInit(); 
        // UART 中断初始化 
        UARTInterruptInit(); 
 
        // 发送字符串 
        // 使能发送 
        GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_HIGH); 
        unsigned char i; 
        for(i = 0; i < 34; i++) 
                UARTCharPut(SOC_UART_1_REGS, Send); 
        // 禁用发送 
        GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_LOW); 
        // 主循环 
        for(;;) 
        { 
//                Receive=UARTCharGet(SOC_UART_1_REGS); 
//                for(i=0;i<200;i++); 
//                // 使能发送 
//                GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_HIGH); 
//                UARTCharPut(SOC_UART_1_REGS, Receive); 
//                // 等待数据发送完成 
//                for(i=0;i<200;i++); 
//                // 禁用发送 
//                GPIOPinWrite(SOC_GPIO_0_REGS, 12, GPIO_PIN_LOW); 
        } 
} 
 
 |   
 
 
 
 |