Hi,
I'm trying to find out without any luck.
I started from periph_adc project, and I was able to read the AD0.0 (P0.23) without problem (the code is in the attachment).
Then I replaced the ADC_CHANNLE with
ADC_CHANNLE_T myADC_CHANNLE
so I can change channel from AD_CH0 to AD_CH7.
Compiling this code it was running well only when myADC_CHANNLE = AD_CH0, else stucked in a while cycle.
Then modified set _LPC_ADC_ID (I saw similar method in a lot of example ):
_LPC_ADC_ID->CR |= 0x01;
hoping I could get AD_CH1 data, but the program get into this cycle:
void HardFault_Handler(void)
{ while(1) {}
}
I was searching a lot for the solution, but can not find more information.
Is there anybody could help me?
Best wishes!
Original Attachment has been moved to: lpcxpresso.txt.zip
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