kinetis的UART串口(DMA模式)
允许接收
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”
- 如何缩短嵌入式系统开发之路(04-14)
- 对Linux内核中进程上下文和中断上下文的理解(04-27)
- 嵌入式应用中的四类1-Wire主机电路设计(08-03)
- 基于C/S架构的通用计算机在线考试系统的实现(08-12)
- 嵌入式WEB服务器在太阳能发电站监测系统中的设计应用(09-08)
- 嵌入式系统教学模式探讨(06-06)