static uint16_t Sense(uint16_t *val){ PINSEL_CFG_Type PinCfg; /* ADC Pin select * P0.23 as AD0.0 */ uint32_t reading = 0; PinCfg.OpenDrain = 0; PinCfg.Portnum = 0; PinCfg.Funcnum = 1; PinCfg.Pinmode = 2; //Pin has neither pull-up nor pull-down PinCfg.Pinnum = 23; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 24; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 25; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 26; PINSEL_ConfigPin(&PinCfg); ADC_ChannelCmd(LPC_ADC,0,ENABLE); ADC_ChannelCmd(LPC_ADC,1,ENABLE); ADC_ChannelCmd(LPC_ADC,2,ENABLE); ADC_ChannelCmd(LPC_ADC,3,ENABLE); ADC_BurstCmd(LPC_ADC,1); // while(!ADC_GlobalGetStatus(LPC_ADC,0)); volatile uint32_t ad; do { ad = LPC_ADC->ADDR0; } while ((ad & ADC_DR_DONE_FLAG) == 0); val[0] = ADC_DR_RESULT(ad); do { ad = LPC_ADC->ADDR1; } while ((ad & ADC_DR_DONE_FLAG) == 0); val[1] = ADC_DR_RESULT(ad); do { ad = LPC_ADC->ADDR2; } while ((ad & ADC_DR_DONE_FLAG) == 0); val[2] = ADC_DR_RESULT(ad); do { ad = LPC_ADC->ADDR3; } while ((ad & ADC_DR_DONE_FLAG) == 0); val[3] = ADC_DR_RESULT(ad); ADC_BurstCmd(LPC_ADC,0); ADC_ChannelCmd(LPC_ADC,0,DISABLE); ADC_ChannelCmd(LPC_ADC,1,DISABLE); ADC_ChannelCmd(LPC_ADC,2,DISABLE); ADC_ChannelCmd(LPC_ADC,3,DISABLE); PinCfg.Funcnum = 0; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; //Pin has neither pull-up nor pull-down PinCfg.Pinnum = 23; // start pin is 23 -> AD0 PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 24; // start pin is 23 -> AD0 PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 25; // start pin is 23 -> AD0 PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 26; // start pin is 23 -> AD0 PINSEL_ConfigPin(&PinCfg); GPIO_SetDir(0, 1<<23, 1); GPIO_SetValue(0, 1<<23); GPIO_SetDir(0, 1<<24, 1); GPIO_SetValue(0, 1<<24); GPIO_SetDir(0, 1<<25, 1); GPIO_SetValue(0, 1<<25); GPIO_SetDir(0, 1<<26, 1); GPIO_SetValue(0, 1<<26); return reading; } |