Hi,
I'm working on a small project with the FRMD-KL27Z (MKL27Z644) board and now I'm stuck.
The final goal is to read out the ADC and send the data to a PC through USB. The ADC to USB connection will be established with DMA.
The ADC is already working as desired and the next step would be to use DMA to transfer the ADC data.
At the moment the data should be written to a single register, this register is read, the data analysed and the value visualised through different LED colors.
This works only if I set DMA_DCR0 START in the main loop.
But I'd like to do this without using the CPU too much, with the direct DMA procedure as mentioned in the reference manual.
Is there any error I'm making, but I can't find?
My registers are set as followed:
SIM_SCGC6_ADC0 = 1
SIM_SCGC6_DMAMUX = 1
SIM_SCGC7_DMA = 1
ADC is working with
ADC0_SC2_DMAEN = 1
ADC0_SC3_ADCO = 1
The DMA only starts on Software command in the main loop.
DMA_DCR0_SAR = ADC0_RA
DMA_DCR0_DAR = Register in RAM
DMA_DCR0_EINT = 1
DMA_DCR0_ERG = 1
DMA_DCR0_CS = 1 (also tried 0)
DMA_DCR0_EADREQ = 1 (also tried 0)
DMA_DCR0_DREQ = 1
DMA_DCR0_SSIZE = 10 (16 bit)
DMA_DCR0_DSIZE = 10 (16 bit)
DMAMUX0_CHCFG0_SOURCE = ADC0
DMAMUX0_CHCFG0_TRIG = 0 (also tried 1)
The initialization works:
- Enable clocks
- Disable ADC, DMA, DMAMUX
- Initialize all Registers
- Enable ADC, DMA, DMAMUX
- set DMA_DSR_BCR0_DONE = 1
- set DMA_DSR_BCR0_BCR = 2 (since 2 Bytes will be transmitted, adc runs in 16 bit signle ended mode)
- ADC calibration
- NVIC Interrupt enable (DMA0)
- main loop starts.
The DMA Interrupt handler does this:
DMA_DSR_BCR0_DONE = 1
DMA_DSR_BCR0_BCR = 2
DMA_DCR0_ERQ = 1
Is there any point I'm missing?
The error seems to be, that the DMA transfer isn't started by the ADC. No data is transfered to the Destination register, and the DMA Interrupt handler is never called.
Thanks,
Hans