目前暂时未实现硬件dma触发,目前使用中断软件触发dma搬运,有待进一步改进.
程序代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| int main(void) { BOARD_InitBootPins(); BOARD_InitBootClocks(); BOARD_InitDebugConsole(); SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; SIM->SCGC6 |= SIM_SCGC6_DMAMUX_MASK; SIM->SCGC7 |= SIM_SCGC7_DMA_MASK; DMAMUX->CHCFG[0] = 0; DMAMUX->CHCFG[0] |= DMAMUX_CHCFG_SOURCE(kDmaRequestMux0Group1ADC0); DMAMUX->CHCFG[0] |= DMAMUX_CHCFG_ENBL_MASK; DMA0->EEI |= DMA_EEI_EEI0_MASK; DMA0->TCD[0].SADDR=(uint32_t)&ADC0->R[0]; DMA0->TCD[0].SOFF =0; DMA0->TCD[0].ATTR =0; DMA0->TCD[0].NBYTES_MLNO=1; DMA0->TCD[0].SLAST=0; DMA0->TCD[0].DADDR=(uint32_t)&result; DMA0->TCD[0].DOFF=0; DMA0->TCD[0].CITER_ELINKNO = (unsigned int)(1); DMA0->TCD[0].DLAST_SGA=0; DMA0->TCD[0].CSR |= (DMA_CSR_INTMAJOR_MASK); DMA0->TCD[0].BITER_ELINKNO = (unsigned int)(1); DMA0->TCD[0].CSR &= ~DMA_CSR_DREQ_MASK; NVIC_EnableIRQ(DMA0_DMA16_IRQn); DMA0->ERQ |= DMA_EARS_EDREQ_0_MASK; ADC0->CFG1 &=~ADC_CFG1_ADLPC_MASK; ADC0->CFG1 |= ADC_CFG1_ADIV(0); ADC0->CFG1 |= ADC_CFG1_ADLSMP_MASK; ADC0->CFG1 |= ADC_CFG1_MODE(0); ADC0->CFG1 |= ADC_CFG1_ADICLK(0); ADC0->CFG2 |= ADC_CFG2_ADLSTS(0); ADC0->CFG2 |= ADC_CFG2_ADHSC_MASK; ADC0->CFG2 &=~ADC_CFG2_ADACKEN_MASK; ADC0->CFG2 |= ADC_CFG2_MUXSEL(0); ADC0->SC2 |= ADC_SC2_DMAEN_MASK; ADC0->SC1[0] = ADC_SC1_ADCH(0x0); ADC0->SC1[0] &= ~ADC_SC1_DIFF_MASK; for(;;) { __asm("NOP"); } }
void DMA0_DMA16_IRQHandler() { gpio_pin_config_t test; test.outputLogic=0; test.pinDirection=kGPIO_DigitalOutput; GPIO_PinInit(GPIOB,17,&test); DMA0->INT |= DMA_INT_INT0_MASK; }
void ADC0_IRQHandler() { DMA0->TCD[0].CSR |=DMA_CSR_START_MASK; }
|