Created
January 27, 2013 22:54
-
-
Save Robotonics/4651105 to your computer and use it in GitHub Desktop.
I2C driver for cmps03 electronic compass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* cmps03.c | |
* | |
* Created on: 26 Jan 2013 | |
* Author: David | |
*/ | |
// driver for cmps03 electronic compass | |
// includes | |
#include "lm4f120h5qr.h" | |
#include "inc/hw_memmap.h" | |
#include "inc/hw_types.h" | |
#include "driverlib/i2c.h" | |
#include "driverlib/debug.h" | |
#include "driverlib/gpio.h" | |
#include "driverlib/pin_map.h" | |
#include "I2C_Stellaris_API.h" | |
#include "utils/uartstdio.h" | |
#include "driverlib/sysctl.h" | |
#include "cmps03.h" | |
// FreeRtos includes | |
#include "priorities.h" | |
#include "FreeRTOS.h" | |
#include "task.h" | |
#include "queue.h" | |
#include "semphr.h" | |
// variables | |
extern int bearing=0; | |
int readValues[2] = {0x00,0x00};// array storing high and low byte of word in register 3 (0-359.9 degrees) | |
int d1,d2,d3,d4; | |
int read_cmps03(void) | |
{ | |
I2CReadData(I2C3_MASTER_BASE, 0xE0, 0x02, readValues, 2); // read registers 2>high byte and 3>low byte | |
bearing=((int)readValues[0] << 8) | ((int)readValues[1]); // store result of read in d1 | |
return bearing; | |
}; | |
void init_quadrants(void) | |
{ | |
/* initialise 4 relative quadrant directions */ | |
I2CReadData(I2C3_MASTER_BASE, 0xE0, 0x02, readValues, 2); // read registers 2>high byte and 3>low byte | |
d1=((int)readValues[0] << 8) | ((int)readValues[1]); // store result of read in d1 | |
d2 = d1 + 900; | |
if (d2 >= 3600) d2 = d2 - 3600; | |
d3 = d2 + 900; | |
if (d3 >= 3600) d3 = d3 - 3600; | |
d4 = d3 + 900; | |
if (d4 >= 3600) d4 = d4 - 3600; | |
return; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment