kinetis的UART串口(DMA模式)
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接收對應(yīng)的DMA1未使用中斷,在這里也同時對其重設(shè)目的地址并啟動
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”
評論