Hi Csaba,
Kerry has good example and if helps that is great.
I reproduced your issue with the periph_adc example.
What I found was the board_sysinit.c Board_SetupMuxing() function is setting up a bunch of pins to default functions including setting up the ADC_CH0 to be used.
The adc.c code does not show that this has magically happened and therefore when you switch the _ADC_CHANNLE #define to something other than ADC_CH0 the desired pin is not configured correctly.
My example changes the to use ADC_CH1 in the adc.c main(). Look for "//DES" in comments.
The condensed code change is here:
#define _ADC_CHANNLE ADC_CH1 //DES was ADC_CH0
/* Chip_IOCON_PinMux(0, 25, IOCON_ADMODE_EN, IOCON_FUNC1); */ //DES old API
/*ADC Init */
#if (_ADC_CHANNLE == ADC_CH1) //DES ADC_CH0 is setup to ADC analog function in board_sysinit.c via the pinmuxing structure. When wanting different ADC channel we need to enable it.
Chip_IOCON_PinMux(LPC_IOCON, 0, 24, IOCON_MODE_INACT, IOCON_FUNC1); //DES new API....enabling ADC_CH1 on port 0 pin 24
#endif
Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
Chip_ADC_EnableChannel(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE);
If you want to setup the desired ADC_CH1 by default you could add the following line into the pinmuxing structure in board_sysinit.c like following:
/* Pin muxing configuration */
STATIC const PINMUX_GRP_T pinmuxing[] = {
{0, 0, IOCON_MODE_INACT | IOCON_FUNC2}, /* TXD3 */
{0, 1, IOCON_MODE_INACT | IOCON_FUNC2}, /* RXD3 */
{0, 4, IOCON_MODE_INACT | IOCON_FUNC2}, /* CAN-RD2 */
{0, 5, IOCON_MODE_INACT | IOCON_FUNC2}, /* CAN-TD2 */
{0, 22, IOCON_MODE_INACT | IOCON_FUNC0}, /* Led 0 */
{0, 23, IOCON_MODE_INACT | IOCON_FUNC1}, /* ADC 0 */
// {0, 24, IOCON_MODE_INACT | IOCON_FUNC1}, /* ADC 1 */ //DES uncomment to added ADC_CH1 as default pin function
{0, 26, IOCON_MODE_INACT | IOCON_FUNC2}, /* DAC */
Regards,
David