Hi
I’m trying to connect to this sensor (via stk500 [Mega88@20MHz])
http://www.sparkfun.com/commerce/produc … cts_id=741
I’m using this code (AVR GCC)
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#define FOSC 20000000
#define BAUD 57600
#define MYUBRR FOSC/16/BAUD-1
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))
#define STATUS_LED 0
//Define functions
//======================
void ioinit(void); // initializes IO
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
//======================
int main (void)
{
ioinit(); //Setup IO pins and defaults
while(1)
{
if (TIFR1 & (1 << OCF1A)) // Flagg tilsvarende 100Hz
{
TIFR1 = (1 << OCF1A); // reset flagg
// Ch 0
ADMUX = (0<<REFS0) | (0<<REFS1) |(0 & 0x1F);
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1 << ADSC) );
ADCSRA |= (1 << ADIF);
printf("%d", ADC);
printf(";");
// Ch 1
ADMUX =(0<<REFS0) | (0<<REFS1) | (1 & 0x1F);
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1 << ADSC) );
printf("%d", ADC);
printf(";");
// Ch 2
ADMUX = (0<<REFS0) | (0<<REFS1) | (2 & 0x1F);
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1 << ADSC) );
printf("%d", ADC);
printf(";");
// Ch 3
ADMUX = (0<<REFS0) | (0<<REFS1) | (3 & 0x1F);
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1 << ADSC) );
printf("%d", ADC);
printf(";");
// Ch 4
ADMUX = (0<<REFS0) | (0<<REFS1) | (4 & 0x1F);
ADCSRA |= (1<<ADSC);
while ( ADCSRA & (1 << ADSC) );
printf("%d", ADC);
printf(";");
printf("\n");
}
}
return(0);
}
void ioinit (void)
{
// 1 = output, 0 = input
// Port 76543210
DDRB = 0b11101111; //PB4 = MISO
DDRC = 0b11111111; //
DDRD = 0b11111110; //PORTD (RX on PD0)
//USART Baud rate: 57600
UBRR0H = MYUBRR >> 8;
UBRR0L = MYUBRR;
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
stdout = &mystdout; //Required for printf init
//ADC
ADMUX = (0<<REFS0) | (0<<REFS1); // For Aref
ADCSRA = (1<<ADEN) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
//Timer
TCCR1B |= (1 << WGM12);
OCR1A = 25000; //100Hz
TCCR1B |= ((0<< CS10) | (1<< CS11) | (0<< CS12)); // Prescaler = 8
}
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
uint8_t uart_getchar(void)
{
while( !(UCSR0A & (1<<RXC0)) );
return(UDR0);
}
On STK500:
Vref = 3.3V
Vtarget = 3.4V
These are connected with wire:
Sensor:____________STK500:
3.3V_______________VTarget
GND________________GND
XAxis______________PC0
YAxis______________PC1
ZAxis______________PC2
Xrate______________PC3
Yrate______________PC4
And my readings are
0;0;0;0;0;
When I connect VTARGET with PC0-PC4 i get
1018;1018;1018;1018;1018;
So the ADC is working…
When I messure the volt between GND and the output pin on the sensor I get1487mV on my gyros and 1622, 1623 and 1901mV on the accelerometers.
It looks like the sensors is working and the ADC is working, but they are not working together…
What can I do to get this working?
Magnus :?: