Hi,
I'm trying to use ADC receive 10 data a time and doing average.
This is almost the same from the adc example, in which the adc acquire 3 samples and do averaging.
The main difference is I used config tool -> peripherals to setup my ADC and DMA, here is the parameters:
ADC:
DMA:
And I copy the code from the example "lpcxpresso55s69_lpadc_dma":
g_DmaTransferDoneFlag = false;
LPADC_DoSoftwareTrigger(ADC0, 1UL);
while ((LPADC_GetStatusFlags(ADC0) & RESULT_FIFO_READY_FLAG) == 0UL)
{
PRINTF("1\r\n");
}
PRINTF("2\r\n");
DMA_StartTransfer(&DMA0_CH0_Handle);
while (false == g_DmaTransferDoneFlag)
{
PRINTF("3\r\n");
}
uint16_t adc_val = (uint16_t)(g_avgADCValue & ADC_RESFIFO_D_MASK);
if (adc_index < sizeof(adc_data_buffer)/sizeof(adc_data_buffer[0])) {
adc_data_buffer[adc_index++] = adc_val;
}
The issue I have is that the code is stuck at
while (false == g_DmaTransferDoneFlag)
{
PRINTF("3\r\n");
}
unless the "FIFO0 WATERMARK" in the peripheral was changed to 0.
I tried to compare the auto generated pheripherals.c with the ADC_Configuration(void) in the example but no luck.
Did I miss some codes, or mass up with some setup?
Hi @waliwalabo
“
The issue I have is that the code is stuck at
while (false == g_DmaTransferDoneFlag)
{
PRINTF("3\r\n");
}
”
This proves that DMA is not worked.
This may be due to ADC not being configured correctly or DMA not being configured correctly.
I think you can check the adc dma registers between sdk demo and your code in debug moed.
BR
Harry
Hi Harry,
Thanks for your suggestion.
I compared the DAM and ADC. I thought my DAM was almost identical to the example and found something interesting in ADC's register:
I took the screen shot when my firmware stuck at the while loop, and FCTRL[0] = 0x00090007.
According to the manual, bit 0:4 is FCOUNT. I tried different watermark like 6 or 8 and when it got stuck, FCOUNT is always smaller than watermark by 2.
Then I changed the watermark to 2 and my code finially work.
So it seems that if the watermark is larger than 3, the FIFO will never receive enough data, no matter what setup I used in config tool.
I change the watermark and SAMPLE_COUNT in the example and it stops working as well.
Did I miss something in the ADC configuration? I don't think this fifo cannot hold more than 3 words. I found FIFOSIZE in the UM and compared with the register, I can confirm that the fifo size of the example and my code is 4. Maybe this is the reason of all the issues but I didn't find the place to change it in the config tool.
What do you think?
Hi @waliwalabo
"I change the watermark and SAMPLE_COUNT in the example and it stops working as well. "
I will try to reproduce this issue in SDK demo.
BR
Harry