M0测试通过的代码
/*---------------------------------------------------------------------------------------------------------*/
/* 程序名称:M0串口通信程序 */
/* 功能:采用M0 62B的FIFO进行通信 */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include "Driver\DrvUART.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvSYS.h"
#include "NUC1xx.h"
/*---------------------------------------------------------------------------------------------------------*/
/* 全局变量 */
/*---------------------------------------------------------------------------------------------------------*/
/*---Using in UART Test -------------------*/
volatile uint8_t buffer[62]; //串口缓冲
uint8_t UART_Flag; //串口标志
/*---------------------------------------------------------------------------------------------------------*/
/* UART 回调函数 */
/*---------------------------------------------------------------------------------------------------------*/
void UART_INT_HANDLE(uint32_t u32IntStatus)
{
uint8_t i;
if(u32IntStatus&DRVUART_RDAINT)
{
if(UART0->ISR.RDA_IF==1)
{
for(i=0;i<62;i++)
{
buffer=UART0->DATA;
UART_Flag=1;
}
}
}
}
//发送一个字节
void SendByte(uint8_t data)
{
while(UART0->FSR.TX_FULL == 1);
UART0->DATA=data;
}
//发送FIFO读取的数据
void SendString(void)
{
uint8_t i;
for(i=0;i<62;i++)
SendByte(buffer);
while(UART0->FSR.TX_EMPTY==0);
}
/****************UART0配置函数***************************************/
void UART0_Config(void)
{
STR_UART_T sParam;
/* Set UART Pin */
DrvGPIO_InitFunction(E_FUNC_UART0); //使能UART0接口
/* Select UART Clock Source From 12Mhz*/
DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC,0); //选择UART接口的时钟位外部12MHz
/* UART Setting */
sParam.u32BaudRate = 9600;
sParam.u8cDataBits = DRVUART_DATABITS_8;
sParam.u8cStopBits = DRVUART_STOPBITS_1;
sParam.u8cParity = DRVUART_PARITY_NONE;
sParam.u8cRxTriggerLevel= DRVUART_FIFO_62BYTES;
if(DrvUART_Open(UART_PORT0,&sParam) != E_SUCCESS)
{
printf("UART0 open failed\n");
}//设定UART0的参数
DrvUART_EnableInt(UART_PORT0,DRVUART_RDAINT,UART_INT_HANDLE);
//使能串口中断,1接收中断状态 2发送保持寄存器空中断使能 3可接受数据中断使能
}
/**********************RCC配置函数****************************/
void RCC_Config(void)
{
/* SYSCLK =>12Mhz*/
UNLOCKREG();
SYSCLK->WRCON.XTL12M_EN = 1;
/* Waiting for 12M Xtal stalble */
DrvSYS_Delay(5000); //系统定时
/* Run 48Mhz */
DrvSYS_Open(48000); // 选择系统时钟
LOCKREG();
}
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main()
{
RCC_Config();
UART0_Config();
while(1)
{
if(UART_Flag==1)
{
UART_Flag=0;
SendString();
}
}
}
|