微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > kinetis的UART串口(DMA模式)

kinetis的UART串口(DMA模式)

时间:11-05 来源:互联网 点击:

允许接收

UART5_C5 = (17)|(15);//允许收、发中断产生DMA请求

UART5_C1 |= 17;//使用回环模式

}

void dma0_init()

{

SIM_SCGC6 |= SIM_SCGC6_DMAMUX_MASK;

DMAMUX_CHCFG0 = (17) | 13;

SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;

DMA_CR = 0;

DMA_TCD0_SADDR = (unsigned long)uart_tx.buf[0];//DMA源地址

DMA_TCD0_DADDR = (unsigned long)UART5_D;//DMA目的地址

DMA_TCD0_NBYTES_MLNO = 1;

DMA_TCD0_ATTR = 0;//8位传送,关闭模特性

DMA_TCD0_SOFF = 1;//每次操作完源地址,源地址增加1

DMA_TCD0_DOFF = 0;//每次操作完目标地址,目标地址不增加

DMA_TCD0_SLAST = 0;//DMA完成一次输出之后即major_loop衰减完之后不更改源地址

DMA_TCD0_DLASTSGA = 0;//DMA完成一次输出之后即major_loop衰减完之后不更改目标地址

DMA_TCD0_CITER_ELINKNO = 100;

DMA_TCD0_BITER_ELINKNO = 100;

DMA_TCD0_CSR = 0;

DMA_TCD0_CSR |= DMA_CSR_INTMAJOR_MASK;

DMA_TCD0_CSR |= DMA_CSR_DREQ_MASK;

NVICISER0 |= 10;//;//使能中断NVICISERn=1

DMA_ERQ |= (1 0);//启动

}

void dma1_init()

{

//SIM_SCGC6 |= SIM_SCGC6_DMAMUX_MASK;

DMAMUX_CHCFG1 = (17) | 12;

//SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;

//DMA_CR = 0;

DMA_TCD1_SADDR = (unsigned long)UART5_D;//DMA源地址

DMA_TCD1_DADDR = (unsigned long)uart_rx.buf[0];//DMA目的地址

DMA_TCD1_NBYTES_MLNO = 1;

DMA_TCD1_ATTR = 0;//8位传送

DMA_TCD1_SOFF = 0;//每次操作完源地址,源地址不增加

DMA_TCD1_DOFF = 1;//每次操作完目标地址,目标地址增加1

DMA_TCD1_SLAST = 0;//DMA完成一次输出之后即major_loop衰减完之后不更改源地址

DMA_TCD1_DLASTSGA = 0;//DMA完成一次输出之后即major_loop衰减完之后不更改目标地址

DMA_TCD1_CITER_ELINKNO = 100;

DMA_TCD1_BITER_ELINKNO = 100;

DMA_TCD1_CSR = 0;

DMA_TCD1_CSR = ~DMA_CSR_INTMAJOR_MASK;

DMA_TCD1_CSR |= DMA_CSR_DREQ_MASK;

DMA_ERQ |= (1 1);//启动

}

int main(void)

{

int i;

MCG_Init();

dma0_init();

dma1_init();

UART_Init();

for(i=0;i100;i++)

{

uart_tx.buf[i] = i;

uart_rx.buf[i] = 0;

}

uart_tx.index = 1;

uart_rx.index = 0;

printf(Hello (Kinetis) World in 'C' from MK60DX256Z derivative! nr);

UART5_C2 |= 13;

for(;;)

{

}

return 0;

}

void dam0_isr(void)

{

static unsigned char cnt=0;

DMA_INT = 0x1; // clear dma int flag

cnt++;

memset(uart_tx.buf,cnt,100);

DMA_TCD0_SADDR = (unsigned long)uart_tx.buf[0];//DMA源地址

DMA_ERQ |= (1 0);//启动

//与UART接收对应的DMA1未使用中断,在这里也同时对其重设目的地址并启动

DMA_TCD1_DADDR = (unsigned long)uart_rx.buf[0];

DMA_ERQ |= (1 1);//启动

}

将“kinetis_sysinit.c”的“__vect_table”中16号中断“(tIsrFunc)UNASSIGNED_ISR”换成“(tIsrFunc)dam0_isr”

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top