> The getADC function that I am talking about is the one in the i2c-io code on
> the robostix. It uses the same line as a2d_10.c to set REFS1 and REFS0 which
> ADMUX = ( ADMUX & (( 1 << REFS1 | ( 1 << REFS0 ))) | mux). I see no mention
> of ADLAR in either code so I have assumed that it is set to right adjusted
> as a default, unless it is set in a config file I have not yet found. The
> actual code is both a2d_10.c and the getADC function in i2c-io are almost
> exact, except one returns ADC and the other sends both ADCL and ADCH back to
> the gumstix. I have not put a voltage on the vref pin so that also remains
> the same.
Hmmm. I'm still not seeing a getADC function. I see the following case
statement in the ProcessCommand function:
I2C_IO_Get_ADC_t *req = (I2C_IO_Get_ADC_t
*)&packet->m_data[ 2 ]; // +1 for cmd, +1 for len
uint8_t mux = req->mux;
// Set ADMUX but don't mess with REFS0 & REFS1
ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | mux;
// Start the conversion
ADCSR = ADCSR | ( 1 << ADSC );
// Wait for it to complete
while ( ADCSR & ( 1 << ADSC ));
packet->m_data[ 0 ] = 2;
packet->m_data[ 1 ] = ADCL;
packet->m_data[ 2 ] = ADCH;
IO_LOG3( "GetADC mux:%d read 0x%02x%02x\n", mux,
packet->m_data[ 2 ], packet->m_data[ 1 ]);
This and a2d_10.c should return the same result, provided the A2D
hawrdware is initialized the same way.
The ADCSR register needs to be initialized, and the PORTF pins need to
be configured as inputs (although this is the default).
Depending on your fuse bit settings, you may also need to disable the
JTAG, since it uses some of the ADC pins.
What values are you getting that don't agree? What happens when you
use known voltages, like 0v, 5v, and say 2.5v?
The ADLAR bit is part of the ADMUX register, so it will be zero in the
So, I suspect that if you're getting different answers, it relates to
initializing the hardware differently.
Vancouver, BC, Canada