用的是M0516- LAN, P3.0作为RXD,P3.1作为TXD
我用的是外部晶振22.1184,9600波特率,串口通讯发送正常,接收无法进入中断,硬件检查过没有问题,这个我的代码,请各位帮我分析分析。。。。谢谢了,不知道怎么回事。。。。。
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <absacc.h>
#include "M051Series.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvSYS.h"
#include "Driver\DrvTIMER.h"
#include "Driver\Drvuart.h"
#define uchar unsigned char
#define uint unsigned int
#define DMX512RXBUFSIZE 512
void Timer0_Callback (void);
/********************相关参数*************************/
uchar buffer[14] = {0xCD,0x0B,0x02,0x00,0x00,0x00,0x00,0x07,0x00,0x01,0x01,0x00,0x01,0xE4};
uchar AirFT,AirFS,b1,b2,KeyNO,MainReg1,LEDCnt;
uchar KeyValidFlag,KeyBit,LED,TData;
uchar ButtonUpFlag,clean,cleanAll,ButtonDownFlag;
/*---Using in DMX512 Test -------------------*/
volatile uint8_t dmx512Rbuf[1024];
volatile uint16_t dmx512Rbytes = 0; /* Available receiving bytes */
volatile uint8_t IsDMX512_1990_ADD=0;
//I0口模式初始化
void IOSetInt()
{
E_DRVGPIO_PIN sPinNumber;
/*set GP0 outpui P2口输出*/
for(sPinNumber=E_PIN0;sPinNumber<=E_PIN7;sPinNumber++)
{
DrvGPIO_Open(E_PORT2,sPinNumber, E_IO_OUTPUT);
}
DrvGPIO_Open(E_PORT3,E_PIN0, E_IO_INPUT ); //RX
DrvGPIO_Open(E_PORT3,E_PIN1, E_IO_OUTPUT ); //TX
DrvGPIO_ClrBit(E_PORT2,E_PIN5);
}
/*************************************************************************************
** Function name: TIMER_Configuration
** Descriptions: TIMER配置
** input parameters: none
** output parameters: none
** Returned value: none
*************************************************************************************/
void TIMER_Configuration()
{
DrvTIMER_Init(); //初始化定时器
DrvSYS_SelectIPClockSource(E_SYS_TMR0_CLKSRC,0); //设定TIMER0的时钟源为外部22.1184MHZ
DrvTIMER_Open(E_TMR0,1000,E_PERIODIC_MODE); //设定定时器timer0的tick周期,并且启动定时器:定时器通道 TMR0 每秒1000次 周期模式
DrvTIMER_SetTimerEvent(E_TMR0,2000,(TIMER_CALLBACK) Timer0_Callback,0); //安装一个定时处理事件到 timer0通道
DrvTIMER_EnableInt(E_TMR0); //使能定时器中断 //TIMER0->TCSR.IE = 1
DrvTIMER_Start(E_TMR0); //定时器timer0开始计数 //TIMER0->TCSR.CEN = 1;
}
/*************************************************************************************
** Function name: Timer0_Callback
** Descriptions: 定时处理事件,1S定时
** input parameters: none
** output parameters: none
** Returned value: none
*************************************************************************************/
void Timer0_Callback (void)
{
if(LED)
{
LEDCnt++;
if(LEDCnt>=5)
{
LED=0;
LEDCnt=0;
//DrvGPIO_SetBit(E_PORT2,E_PIN5);
TData=1;
}
}
}
void Uart_INT_HANDLE(void)
{
volatile char addr;
volatile char regRX;
if((UART0->ISR.RLS_INT ==1) && (UART0->ISR.RDA_INT == 1))
{
if(UART0->FSR.BIF ==1) /* FSR.BIF */
{
addr = UART0->DATA;
UART0->FSR.BIF =1; /* clear ADD_IF flag */
UART0->FSR.FEF =1;
UART0->FSR.PEF =1;
dmx512Rbytes =0;
// printf("\n\rDA%02X ", addr);
IsDMX512_1990_ADD =1;
}
}
else
if((UART0->ISR.RDA_INT == 1)) /* Rx Ready */
{
regRX = UART0->DATA;
dmx512Rbuf[dmx512Rbytes++] = regRX;
// printf("%02X ", regRX);
}
}
/*************************************************************************************
** Function name: USART_Configuration
** Descriptions: 配置USART
** input parameters: none
** output parameters: none
** Returned value: none
*************************************************************************************/
void USART_Configuration()
{
STR_UART_T param;
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0); // 使能UART时钟
DrvSYS_SetClockDivider(E_SYS_UART_DIV,0); //设置为不再分频
DrvGPIO_InitFunction(E_FUNC_UART0); // 复用功能引脚设置
param.u32BaudRate = 5000; // 波特率 9600//双倍速度(22.1184*2)
param.u8cDataBits = DRVUART_DATABITS_8; // 数据位
param.u8cStopBits = DRVUART_STOPBITS_1; // 停止位
param.u8cParity = DRVUART_PARITY_NONE; // 校验位
param.u8cRxTriggerLevel = DRVUART_FIFO_1BYTES; // FIFO存储深度 1 字节
if(DrvUART_Open(UART_PORT0,¶m) != E_SUCCESS)
{
printf("UART0 open failed\n");
}
}
/*******************************************************************/
uchar KeyScan()//扫描一列,有按键返回‘1’,无按键返回’0‘
{
if(DrvGPIO_GetBit(E_PORT1,E_PIN4)== 0) KeyNO=1;//短按风速加按键(默认),进入空调风速选择界面,长按风速按键5秒进入空调模式选择界面,同时按下风速按键和开关键进入温控补偿值设置界面
else if(DrvGPIO_GetBit(E_PORT1,E_PIN3)== 0) KeyNO=2;//温度减
else if(DrvGPIO_GetBit(E_PORT1,E_PIN2)== 0) KeyNO=3;//开/关键//同时按下风速按键和开关键进入温控补偿值设置界面
else if(DrvGPIO_GetBit(E_PORT1,E_PIN1)== 0) KeyNO=4;//温度加
else return 0;
return 1;
}
int main (void)
{
uint i;
/* SYSCLK =>12Mhz*/
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
LOCKREG();
SystemCoreClockUpdate();
IOSetInt();
TIMER_Configuration();
USART_Configuration();
DrvUART_Write(UART_PORT0,buffer,14) ;
DrvUART_EnableInt(UART_PORT0, (DRVUART_RLSINT | DRVUART_RDAINT),(PFN_DRVUART_CALLBACK*)Uart_INT_HANDLE);
while(1)
{
if(IsDMX512_1990_ADD)
{
IsDMX512_1990_ADD=0;
DrvGPIO_ClrBit(E_PORT2,E_PIN6);
printf("\n\rDMX%02X ", dmx512Rbuf[0]);
for(i=0;i<DMX512RXBUFSIZE+3;i++)
{
printf("%02X ", dmx512Rbuf);
}
}
}
}
|
|