Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 182 → Rev 183

/avr/compass-test/compassTest.c
0,0 → 1,138
/****************************************************************************
*
* Copyright (c) 2007 Jon Hylands <jon@huv.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
****************************************************************************/
 
#define F_CPU 8000000UL
 
/* ---- Include Files ---------------------------------------------------- */
 
#include <avr/io.h>
#include <stdio.h>
#include <string.h>
#include <avr/eeprom.h>
#include <stdlib.h>
#include <math.h>
 
#include "Delay.h"
#include "Log.h"
#include "Timer.h"
#include "UART.h"
#include "compassTest.h"
#include "i2cmaster.h"
 
/* ---- Public Variables ------------------------------------------------- */
 
 
/* ---- Private Constants and Types -------------------------------------- */
 
// Our LED is connected to PD2
 
#define LED_DDR DDRD
#define LED_PORT PORTD
#define LED_MASK (1 << 2)
 
/* ---- Private Variables ------------------------------------------------ */
 
 
/* ---- Functions -------------------------------------------------------- */
 
 
 
/////////////////////////////////////////////////////
//
// Turn on the LED
//
 
static inline void turnOnLED (void)
{
LED_PORT |= LED_MASK;
}
 
/////////////////////////////////////////////////////
//
// Turn off the LED
//
 
static inline void turnOffLED (void)
{
LED_PORT &= ~LED_MASK;
}
 
 
/////////////////////////////////////////////////////
//
// HMC 6343 Compass Module Test
//
 
int main (void)
{
uint16_t heading;
int16_t pitch, roll;
uint16_t headingIntegerPart, headingFractionPart;
int16_t pitchIntegerPart, pitchFractionPart;
int16_t rollIntegerPart, rollFractionPart;
 
// initialize the hardware stuff we use
InitTimer ();
InitUART ();
i2c_init ();
 
fdevopen (UART0_PutCharStdio, UART0_GetCharStdio);
 
// set the LED port for output
LED_DDR |= LED_MASK;
 
printf ("\nHoneywell HMC6343 I2C Compass Test\n\n");
 
// Flash the LED for 1/2 a second...
turnOnLED ();
ms_spin (500);
turnOffLED ();
 
while (1) // outer loop is once every 250 ms (more or less)
{
// send the HEADING command to the compass
i2c_start_wait (COMPASS_ADDRESS_WRITE);
i2c_write (COMPASS_HEADING_COMMAND);
 
// now read the response
i2c_rep_start (COMPASS_ADDRESS_READ);
heading = (i2c_readAck () * 256) + i2c_readAck ();
pitch = (i2c_readAck () * 256) + i2c_readAck ();
roll = (i2c_readAck () * 256) + i2c_readNak ();
i2c_stop ();
 
headingIntegerPart = heading / 10;
headingFractionPart = heading - (headingIntegerPart * 10);
pitchIntegerPart = pitch / 10;
pitchFractionPart = pitch - (pitchIntegerPart * 10);
if (pitchFractionPart < 0)
pitchFractionPart *= -1;
rollIntegerPart = roll / 10;
rollFractionPart = roll - (rollIntegerPart * 10);
if (rollFractionPart < 0)
rollFractionPart *= -1;
 
printf ("Heading: %3d.%1d Pitch: %3d.%1d Roll: %3d.%1d\n", headingIntegerPart, headingFractionPart, pitchIntegerPart, pitchFractionPart, rollIntegerPart, rollFractionPart);
 
turnOnLED ();
ms_spin (100);
turnOffLED ();
ms_spin (150);
}
 
// we'll never get here...
return 0;
}
 
/avr/compass-test/Config.h
0,0 → 1,27
/****************************************************************************
*
* Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
****************************************************************************/
 
#if !defined( CONFIG_H )
#define CONFIG_H
 
#define CFG_USE_UART0 1
#define CFG_UART0_BAUD_RATE 19200
#define CFG_UART0_RX_BUFFER_SIZE 64
#define CFG_UART0_TX_BUFFER_SIZE 64
#define CFG_UART0_LF_TO_CRLF 1
 
#endif // CONFIG_H
 
 
/avr/compass-test/compassTest.h
0,0 → 1,46
/****************************************************************************
*
* Copyright (c) 2007 Jon Hylands <jon@huv.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
****************************************************************************/
/**
*
* @file compassTest.h
*
* @brief Contains definitions for an ATmega168 interfacing to a Honeywell HMC6364
* 3-axis solid state tilt compensated compass over I2C
*
****************************************************************************/
 
#if !defined( COMPASS_TEST_H )
#define COMPASS_TEST_H /**< Include Guard */
 
#define TRUE 1
#define FALSE 0
 
#define COMPASS_ADDRESS_WRITE 0x32
#define COMPASS_ADDRESS_READ 0x33
 
#define COMPASS_RAW_ACCEL_COMMAND 0x40
#define COMPASS_RAW_MAG_COMMAND 0x45
#define COMPASS_HEADING_COMMAND 0x50
#define COMPASS_TILT_COMMAND 0x55
 
#define COMPASS_POST_OP_MODE_COMMAND 0x65
 
#define COMPASS_CALIBRATION_COMMAND 0x71
#define COMPASS_END_CALIBRATION_COMMAND 0x7E
 
#define COMPASS_READ_EEPROM_COMMAND 0xE1
#define COMPASS_WRITE_EEPROM_COMMAND 0xF1
 
#endif /* COMPASS_TEST_H */
/avr/compass-test/Makefile
0,0 → 1,19
###########################################################################
#
# bioloid-io Makefile
#
###########################################################################
 
MK_OS = avr
MK_AVR_MCU = m168
MK_AVR_FREQ = 8MHz
 
MK_AVR_PROGRAMMER ?= stk500
 
# Extended fuse byte should be FB for standalone, FA for bootloader-stk500
MK_AVR_FUSES_m168 = F9 DD E2
 
MK_HEX_TARGET = compassTest
MK_SRC_FILES = compassTest.c UART.c Delay.c Log.c StrPrintf.o Timer.c i2cmaster.c
 
include ../../rules/mkRules.mk