I'm pretty new to all this. Just started developing for Kinetis with KSDK 2.0 and have some problems. I think I don't understand every detail completely.
I want to start one ADC conversion with software trigger. After finished conversion the result should be copied to SRAM. I used the examples for MemoryToMemory copy and the interrupt example for ADC.
Both alone work fine, but when I want to combine this the callback is never fired. I think the problem might be my ADC initialisation.
#define ADC_BASEADDR (ADC1)
#define ADC_CHANNEL_GROUP (0U)
#define ADC_USER_CHANNEL (18U)
#define ADC_DR (ADC_BASEADDR->R[ADC_CHANNEL_GROUP])
#define DMA_BASEADDR (DMA0)
#define DMA_CHANNEL (3)
#define BUFFER_SIZE (8)
static void initADC(void) {
adc16_config_t adc16ConfigStruct;
ADC16_GetDefaultConfig(&adc16ConfigStruct);
ADC16_Init(ADC_BASEADDR, &adc16ConfigStruct);
ADC16_EnableHardwareTrigger(ADC_BASEADDR, true);
ADC16_EnableDMA(ADC_BASEADDR, true);
g_adc16ChannelConfigStruct.channelNumber = ADC_USER_CHANNEL;
g_adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false;
}
static void initDMA(void) {
memset(adc_mem, 0x55, sizeof(adc_mem));
/* Configure DMAMUX */
DMAMUX_Init(DMAMUX0);
DMAMUX_SetSource(DMAMUX0, DMA_CHANNEL, 41);
DMAMUX_EnableChannel(DMAMUX0, DMA_CHANNEL);
edma_config_t edma_config;
edma_transfer_config_t transfer_config;
/* Init the eDMA driver */
EDMA_GetDefaultConfig(&edma_config);
EDMA_Init(DMA_BASEADDR, &edma_config);
EDMA_CreateHandle(&edma_handle, DMA_BASEADDR, DMA_CHANNEL);
EDMA_SetCallback(&edma_handle, dmaCallback, NULL);
EDMA_PrepareTransfer(&transfer_config, &ADC_DR, 2, adc_mem, 2, 1, 1, kEDMA_PeripheralToMemory);
if (EDMA_SubmitTransfer(&edma_handle, &transfer_config) == kStatus_Success) {
PRINTF("\r\nEDMA Submit Transfer: Success\r\n");
} else {
PRINTF("\r\nEDMA Submit Transfer: Failed\r\n");
}
EDMA_StartTransfer(&edma_handle);
}
int main(void) {
uint8_t msg = ' ';
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
PRINTF("\r\nPress any key to start demo.\r\n");
GETCHAR();
PRINTF("\r\nInitializing ADC\r\n");
initADC();
PRINTF("\r\nInitializing DMA\r\n");
initDMA();
while (1) {
PRINTF("Destination Buffer:\r\n");
int i = 0;
for (i = 0; i < BUFFER_SIZE; i++) {
PRINTF("%d\t", adc_mem[i]);
}
ADC16_SetChannelConfig(ADC_BASEADDR, ADC_CHANNEL_GROUP, &g_adc16ChannelConfigStruct);
while (dmadone != true)
;
PRINTF("\r\nDMA DONE\r\n");
}
}
Ok, now I got it working. Wasn't so wrong.
Here is the code that has to be changed.
static void initADC(void) {
...
ADC16_EnableHardwareTrigger(ADC_BASEADDR, false);
ADC16_EnableDMA(ADC_BASEADDR, true);
...
}
static void initDMA(void) {
...
EDMA_PrepareTransfer(&transfer_config, &ADC_DR, 2, adc_mem, 2, 2, 2, kEDMA_PeripheralToMemory);
...
}
I had to change the size to 2 for bytesEachRequest and transferBytes. Now its copying my one byte.