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 )
{
break;
}
}
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