-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "oswlib/settings.h" | ||
#include "oswlib/I2C/i2c.h" | ||
#include "oswlib/Sensors/MMA8451.h" | ||
|
||
MMA8451STR MMA8451 = { | ||
MMA8451_SA0_GND, | ||
_i2c_MMA8451_init, | ||
_i2c_MMA8451_ID, | ||
}; | ||
|
||
void _i2c_MMA8451_init(T_UBYTE addr) | ||
{ | ||
MMA8451.address = addr; | ||
I2C.enable(I2C.address); | ||
//I2C.mode(I2C_FAST); | ||
} | ||
|
||
T_UBYTE _i2c_MMA8451_ID( ) | ||
{ | ||
register int j; | ||
|
||
I2C.start(MMA8451.address); | ||
I2C.send( (T_UBYTE) MMA8451_WHO_AM_I ); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4) | ||
I2C.end(0); | ||
|
||
//for(j = 0; j < 250; j++); | ||
|
||
I2C.requestFrom(MMA8451.address, 1); | ||
|
||
if(I2C.available()) | ||
return (T_UBYTE)I2C.read(); | ||
else | ||
return 0x99; | ||
} | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef OSWARRIOR_MCP4725_H_ | ||
#define OSWARRIOR_MCP4725_H_ | ||
|
||
#define MMA8451_SA0_GND 0x1C // Address if A0 is connected to GND or not connected | ||
#define MMA8451_SA0_VCC 0x1D // Address if A0 is connected to VCC | ||
|
||
#define MMA8451_WHO_AM_I 0x0D // Writes data to the DAC | ||
|
||
#define MMA8451_OUT_X_MSB 0x01 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
#define MMA8451_OUT_X_LSB 0x02 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
|
||
#define MMA8451_OUT_Y_MSB 0x03 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
#define MMA8451_OUT_Y_LSB 0x04 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
|
||
#define MMA8451_OUT_Z_MSB 0x05 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
#define MMA8451_OUT_Z_LSB 0x06 // Writes data to the DAC and the EEPROM (persisting the assigned value after reset) | ||
|
||
/* | ||
** =================================================================== | ||
** Function prototypes | ||
** =================================================================== | ||
*/ | ||
|
||
extern void _i2c_MMA8451_init(T_UBYTE addr); | ||
extern T_UBYTE _i2c_MMA8451_ID(void); | ||
|
||
/* | ||
** =================================================================== | ||
** MCP4725 DAC Structure Definition | ||
** =================================================================== | ||
*/ | ||
|
||
typedef struct{ | ||
T_UBYTE address; | ||
void (*init)(T_UBYTE addr); | ||
T_UBYTE (*queryID)(void); | ||
}MMA8451STR; | ||
|
||
extern MMA8451STR MMA8451; | ||
|
||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "oswlib/settings.h" | ||
#include "oswlib/I2C/i2c.h" | ||
#include "oswlib/Sensors/PCF8574.h" | ||
|
||
PCF8574STR PCF8574 = { | ||
PCF8574_ADD0, | ||
_i2c_PCF8574_init, | ||
_i2c_PCF8574_write, | ||
_i2c_PCF8574_read, | ||
}; | ||
|
||
void _i2c_PCF8574_init(T_UBYTE addr) | ||
{ | ||
PCF8574.address = addr; | ||
I2C.enable(I2C.address); | ||
//I2C.mode(I2C_FAST); | ||
} | ||
|
||
void _i2c_PCF8574_write(T_UBYTE data) | ||
{ | ||
I2C.start(PCF8574.address); | ||
I2C.send(data); | ||
I2C.end(1); | ||
return; | ||
} | ||
|
||
T_UBYTE _i2c_PCF8574_read( ) | ||
{ | ||
|
||
I2C.requestFrom(PCF8574.address, 1); | ||
|
||
if(I2C.available()) | ||
return I2C.read(); | ||
else | ||
return 0; | ||
} | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef OSWARRIOR_PCF8574_H_ | ||
#define OSWARRIOR_PCF8574_H_ | ||
/* | ||
** =================================================================== | ||
** Device addressing | ||
** =================================================================== | ||
*/ | ||
|
||
#define PCF8574_ADD0 0x20 // Address if A2 = 0, A1 = 0 y A0 = 0 | ||
#define PCF8574_ADD1 0x21 // Address if A2 = 0, A1 = 0 y A0 = 1 | ||
#define PCF8574_ADD2 0x22 // Address if A2 = 0, A1 = 1 y A0 = 0 | ||
#define PCF8574_ADD3 0x23 // Address if A2 = 0, A1 = 1 y A0 = 1 | ||
#define PCF8574_ADD4 0x24 // Address if A2 = 1, A1 = 0 y A0 = 0 | ||
#define PCF8574_ADD5 0x25 // Address if A2 = 1, A1 = 0 y A0 = 1 | ||
#define PCF8574_ADD6 0x26 // Address if A2 = 1, A1 = 1 y A0 = 0 | ||
#define PCF8574_ADD7 0x27 // Address if A2 = 1, A1 = 1 y A0 = 1 | ||
|
||
/* | ||
** =================================================================== | ||
** Function prototypes | ||
** =================================================================== | ||
*/ | ||
|
||
extern void _i2c_PCF8574_init(T_UBYTE); | ||
extern void _i2c_PCF8574_write(T_UBYTE); | ||
extern T_UBYTE _i2c_PCF8574_read(void); | ||
|
||
/* | ||
** =================================================================== | ||
** MCP4725 DAC Structure Definition | ||
** =================================================================== | ||
*/ | ||
|
||
typedef struct{ | ||
T_UBYTE address; | ||
void (*init)(T_UBYTE addr); | ||
void (*write)(T_UBYTE); | ||
T_UBYTE (*read)(void); | ||
}PCF8574STR; | ||
|
||
extern PCF8574STR PCF8574; | ||
|
||
#endif |