Hi,
I am currently working on a project in which MSPM0G3507 MCU is going to be used. So I currently working with LP-MSPM0G3507 EVK to test the peripherals.
One requirment is that one ADC pin is used to detect 4-Buttons input (PA. In this case, I don't need ADC interrupt so I use polling method (for single channel conversion which is triigered by software) to read ADC input pin and display the output ADC result on OLED display (just for the test purpose). One issue I am facing with at the moment is that ADC single conversion output results in '0' (which can be seen from OLED display) whichever buttons I pressed in Run mode.
But when go into debug mode and put a breakpoint @DL_ADC12_getMemResult or any statement, the ADC output result variable shows the correct value according to the pressed Button and then OLED can also display the same ADC output result value. Or if I add 500ms of Delay after ADC conversion or end of the function loop, the correct ADC output result can be seen on the display in run mode as well.
May I know how this issue can be resolved?
FYI,
int main(void) { SYSCFG_DL_init(); OLED_Init(); while (1) { // Read ADC pin g_u16ADCVal = ADCButtons_analogRead(); // Display u8g2_ClearBuffer(&u8g2); u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr); u8g2_DrawStr(&u8g2, 0, 10, u8x8_u16toa(g_u16ADCVal, 4)); u8g2_SendBuffer(&u8g2); } } uint16_t ADCButtons_analogRead () { volatile uint16_t g_u16ADCResult; DL_ADC12_startConversion(ADC12_0_INST); while( DL_ADC12_getRawInterruptStatus(ADC12_0_INST, DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED) != DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED) ; DL_ADC12_clearInterruptStatus(ADC12_0_INST, DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED); g_u16ADCResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0) & 0x0FFF; //delay(16000000);//Worked in Run Mode if this 500ms delay is added. DL_ADC12_enableConversions(ADC12_0_INST); return g_u16ADCResult; }
Thanks so much in Advance.