Hi,
I have been working on a project where I am supposed to implement RNG using ADC. The problem is, that I cannot get ADC to work using LPCOpen or registers. Everything is well otherwise, but the status bit never goes to 1, so the program gets stuck in loop waiting for it.
ADC code using registers:
LPC_SYSCTL->PCONP |= (1 << 12) | (1 << 15); // Power/Clock ON
LPC_ADC->CR = 7 | (3 << 8) | (1 << 16) | (1 << 21);
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 23, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 25, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Uint32 data = 0;
do{
data = LPC_ADC->DR[0];
}while((data & 1<<31) == 0);
data = data >> 4;
data = data & 0xFFF;
ADC code using LPCOpen:
static ADC_CLOCK_SETUP_T ADCSetup;
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 23, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 25, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_ADC_Init(LPC_ADC, &ADCSetup);
Chip_ADC_SetSampleRate(LPC_ADC, &ADCSetup, ADC_MAX_SAMPLE_RATE);
Chip_ADC_SetBurstCmd(LPC_ADC, LPC_ENABLE);
Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, LPC_ENABLE);
Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, LPC_ENABLE);
Chip_ADC_EnableChannel(LPC_ADC, ADC_CH2, LPC_ENABLE);
uint16_t data0, data1, data2;
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH0, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &data0);
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, &data0);
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH2, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH2, &data2);
Solved! Go to Solution.
I finally got it working, there was a bit of miscommunication between our HW dev and I. The RTC was changed and the values used for ADC did not match.
Thank you very much for all the help!
Hi @Mashau
I hope you are doing well!
If I understood properly , you are not able to exit this loop.
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CHx, ADC_DR_DONE_STAT) != SET);
If yes, could you try the periph_adc example with this modification?
That is : After the ADC channel has been enabled call App_Polling_Test(); function, avoiding all the following part of the example.
In my case, I am currently able to debug with the LPC1769, its ADC has less features than the LPC407x , but they share the same adc_17xx_40_xx.c driver.
I was able to get the ADC conversion ( exit the while(Chip_ADC_ReadStatus)). I have also hardcoded the burst flag, to do a quick test of your setting with this mode. Apparently it worked on my side.
What are your results?
Diego.
Yes, you are correct, the program gets stuck on that loop.
I tried the LPCOpen ADC example and the end result is the same, it gets stuck in loop.
Hi @Mashau
Thanks for your reply.
I think that we could also check from the hardware side. For example , ensure to have the ADC supply voltage VREFP, and VDDA/VSS references according to the DS and UM specifications. Verify that the ADC pins input voltage does not exceed VSS to VREFP measurement rage. Try an ADC channel that you never used before.
All the best
Diego.
Yes, VREFP and VDDA are tied to 3,3 V and VSSA is tied to ground.
Tried channels 0, 1 and 2, none of which work.
Hi @Mashau
Thank you for your reply!
I am thinking in the following:
* Check the return value for the function readADC val.
Are you getting an error? No valid conversion results for any ADC channel?
* And Check the return of the function Chip_ADC_ReadStatus() for the ADC_DR_OVERRUN_STAT status
To see, if you are getting an overrun status as you enabled burst mode.
* Try testing without enabling burst mode.
* Check what happens with other ADC channels, different than 0 , 1 and 2.
* If , possible, check if this can be replicable with other parts of yours.
I tested your code with the LPCopen drivers , with my LPC1769, and I was able to get out of the while loop (as ADC conversions complete ). When not, it was because I did not called (on purpose) the function Chip_ADC_EnableChannel() for a specific channel.
I hope this could help
Diego.
I finally got it working, there was a bit of miscommunication between our HW dev and I. The RTC was changed and the values used for ADC did not match.
Thank you very much for all the help!