Skip to content

Commit

Permalink
added code to flush the adc channel's fifo if not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
holla2040 committed Dec 12, 2014
1 parent 4f34030 commit b1936cf
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions hardware/cc3200/cores/cc3200/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,35 @@ void analogWrite(uint8_t pin, int val) {

uint16_t analogRead(uint8_t pin)
{
uint16_t channel;

uint16_t pinNum = digitalPinToPinNum(pin);

switch(pinNum) {
case PIN_57: {channel = ADC_CH_0;}break;
case PIN_58: {channel = ADC_CH_1;}break;
case PIN_59: {channel = ADC_CH_2;}break;
case PIN_60: {channel = ADC_CH_3;}break;
default: return 0;
}

PinTypeADC(pinNum,0xFF);
ADCChannelEnable(ADC_BASE, channel);
ADCTimerConfig(ADC_BASE,2^17);
ADCTimerEnable(ADC_BASE);
ADCEnable(ADC_BASE);

while(!ADCFIFOLvlGet(ADC_BASE, channel));

uint16_t val = ADCFIFORead(ADC_BASE, channel) & 0x3FFF;

ADCDisable(ADC_BASE);
ADCChannelDisable(ADC_BASE, channel);
ADCTimerDisable(ADC_BASE);

val = val >> 2;
return val;
uint16_t channel,val;
uint16_t pinNum = digitalPinToPinNum(pin);

switch(pinNum) {
case PIN_57: {channel = ADC_CH_0;}break;
case PIN_58: {channel = ADC_CH_1;}break;
case PIN_59: {channel = ADC_CH_2;}break;
case PIN_60: {channel = ADC_CH_3;}break;
default: return 0;
}

while(ADCFIFOLvlGet(ADC_BASE, channel)) { // flush the channel's FIFO if not empty
ADCFIFORead(ADC_BASE, channel);
}

PinTypeADC(pinNum,0xFF);
ADCChannelEnable(ADC_BASE, channel);
ADCTimerConfig(ADC_BASE,2^17);
ADCTimerEnable(ADC_BASE);
ADCEnable(ADC_BASE);

while(!ADCFIFOLvlGet(ADC_BASE, channel));
val = ADCFIFORead(ADC_BASE, channel) & 0x3FFF;

ADCDisable(ADC_BASE);
ADCChannelDisable(ADC_BASE, channel);
ADCTimerDisable(ADC_BASE);

val = val >> 2;
return val;
}

0 comments on commit b1936cf

Please sign in to comment.