Hello to the AVR community.
I have written a code that take analog values from my hardware and through a bluetooth working in serial port profile displays data on the hyperterminal.I am using an atmega168 processor.
I successfully, after a lot of struggle was able to transmit data over the UART and was able to display float values but the values that I get are incorrect.
I am posting my code below....any help or suggestions as to why I get a constant stream of -64's for all my analog values would be really helpful.
Code:
uint16_t readADC(int pin)
{
uint8_t low, high;
uint16_t sample;
ADMUX =(1<<ADLAR)|(0<<REFS1)|(0<<REFS0)|(pin & 0x0F);
ADCSRA|=(1<<ADEN)| (1<<ADIF)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
// start conversion
ADCSRA|= (1<<ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
low = ADCL;
high = ADCH;
// combine the two bytes
sample = (high << 8) | (low & 0xFF);
return sample;
}
Result :
Vout=-64 Vbias=-64 X=-64 Y=-64 Z=-64, Number:295 |