RLP G120 Analog reading

Hi, I’m trying to read an analog value on channel1 of the G120 board using RLP and I’m having the following issue:

When I execute the reading doing a simple call to the RLP function everything goes well.
I have an ISR installed on RLP using the external interrupt 1 (P2_11), if I try to call the analog reading function I get the overrun bit on after the conversion and the value is wrong.

My analog reading function enables only the channel 1 on polling mode, no burst and the interrupt bit is disabled, I start the conversion manually and wait for the done bit to be enabled.

Any idea why the RLP code works when I call it from the .Net Managed code and why it doesn’t when it’s called inside an RLP isr?

There is a better way to read an analog value on the G120 using RLP?

Here is my RLP read analog function, I’m returning the whole result register so I can check the done bit and overrun bit later (31 and 30)

uint32_t ADCRead( uint8_t channelNum )
	uint32_t regVal, ADC_Data;
	uint32_t adcCR, adcIntEn;

	/* channel number is 0 through 7 */
	if ( channelNum >= ADC_NUM )
	channelNum = 0;		/* reset channel number to 0 */

	adcCR = LPC_ADC->CR;
	adcIntEn = LPC_ADC->INTEN;

	LPC_ADC->INTEN = 0; // Disable all interrupts for AD0

	LPC_ADC->CR = 0x200400; // No pin on ADC0, clock division by 4, no burst, A/D is operational
	LPC_ADC->CR |= (1 << 24) | (1 << channelNum);	// Start the conversion on selected channel
	/* switch channel,start A/D convert */
	while ( 1 )			/* wait until end of A/D convert */
		regVal = LPC_ADC->DR[channelNum];
		/* read result of A/D conversion */
		if ( regVal & ADC_DONE )
	LPC_ADC->CR &= (0xF8FFFFFF);	/* stop ADC now  */
	// restore the old values
	LPC_ADC->CR = adcCR;
	LPC_ADC->INTEN = adcIntEn;
	// if ( regVal & ADC_OVERRUN )	/* save data when it's not overrun, otherwise, return zero */
	// {
	//return ( 0 );
	// }
	ADC_Data = regVal;//( regVal >> 4 ) & 0xFFF;
	return ADC_Data;	/* return A/D conversion value */

Thanks in advance

How is your external interrupt triggered?

Hi @ Architect, my interrupt is triggered using the following sample that I’ve uploaded on codeshare:


Basically I’m using the following function to install the interrupt:

RLPext->Interrupt.Install(EINT1_IRQn, Interrupt1Handler, NULL)

Where EINT1_IRQn is the ext int #1 number (19)

On the Interrupt1Handler function is where I have the call to the analog reading, and it keeps having the overrun bit enabled with some invalid readings.

I will try to use the RLPext->Interrupt.Uninstall to try uninstall the ext and the analog reading interrupts, however I have disabled the interrupt bit on the ADC.

Any ideas will be greatly appreciated.

An update I’ve double checked my code and realize that I can’t get any valid reading from the ADC on RLP with or without the interrupt.

So my question will be how do I get an analog reading from a G120 channel on RLP?

After a lot of testing I’m using the initial function posted here to read from the analog input, my only change is instead of using the clock division by 4 I’m using 255 to use the lower speed that I can this allows me to read a value that I think is right but the Overrun bit is still enable.

Anyone with a better/proper way to read an analog input in a G120 board using RLP code?


I have completed RLP code to read from the G120 ADC. Let me know if this is useful to you, I can email if you wish.

Although this post is archived, an attempt was made nonetheless. :slight_smile:


I am also interested in this topic. Please send me your RLP code

I am also interested in this code. Where, how can I get the RLP code?