本帖最后由 詹求实 于 2020-6-27 10:53 编辑
#include "common.h"
#include "rtc.h"
#include "uart.h"
#include "dma.h"
#include "uart_dma_app.h"
#include "sysinit.h"
#define SEND_BUF_LEN 50
uint8_t send_buf[SEND_BUF_LEN]; //发送缓冲区
void printf_int(int8* str)
{
uint16 len = 0;
while(*str)
{
send_buf[len++] = *str;
str++;
if (len >= (SEND_BUF_LEN-1))
{
send_buf[SEND_BUF_LEN-1] = 0;
break;
}
}
DMA_SetMajorLoopCounter(DMA,len,DMA_CHANNEL0);//设置主循环迭代次数
DMA_sLastAddressAdjust(DMA,-len,DMA_CHANNEL0); //主循环结束后将源地址调整到初始值
DMA_EnableRequest(DMA,DMA_CHANNEL0); /*使能通道硬件请求信号*/
}
/******************************************************************************/
int main (void)
{
UART_ConfigType sConfig;
DMA_ConfigType DMA_Config={0};
/*执行系统初始化*/
sysinit();
LED0_Init();//初始化 LED
printf("\nRunning the UART_DmaSend_demo project.\r\n");
DMA_int(DMA,&DMA_Config); /*初始化DMA模块*/
UART_DMASendInit(UART1,send_buf,1,DMA_CHANNEL0);
DMA_DisableRequest(DMA,DMA_CHANNEL0);//禁用通道硬件请求信号
sConfig.u32SysClkHz = BUS_CLK_HZ;//选择系统时钟
sConfig.u32Baudrate = 115200;//配置波特率为115200
UART_Init(UART1,&sConfig);//初始化串口 0
UART_EnableDMA(UART1,TxDMA); /*发送器位空的时候,选择DMA向发送器出传输数据*/
printf_int("\nPrint characters using dma mode.\r\n");
while (!GetChannelDoneFlag(DMA,DMA_CHANNEL0)); /* 等待发送完成 */
LED0_Toggle();
printf_int("\nrepeat Print characters using dma mode.\r\n");
while (!GetChannelDoneFlag(DMA,DMA_CHANNEL0)); /* 等待发送完成 */
LED0_Toggle();
while (1)
{
}
}
|