Skip to content

Commit

Permalink
Soporte para sensores agregado
Browse files Browse the repository at this point in the history
  • Loading branch information
argandas committed Apr 10, 2014
1 parent 280a784 commit e9e92c6
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sensors/MCP4725.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ void _i2c_MCP4725_setVoltage( T_ULONG output, T_BOOLEAN writeEEPROM )
{
I2C.start(MCP4725.address);


if (writeEEPROM)
{
//I2C.send(MCP4725_CMD_WRITEDACEEPROM);
}
else
{
//I2C.send(MCP4725_CMD_WRITEDAC);
I2C.send( (T_UBYTE)(0x000F & (output>>8)) ); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
I2C.send( (T_UBYTE)(0x00FF & (output)) ); // Lower data bits (D3.D2.D1.D0.x.x.x.x)
}

I2C.send( (T_UBYTE)(0x000F & (output>>8)) ); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4)
I2C.send( (T_UBYTE)(0x00FF & (output)) ); // Lower data bits (D3.D2.D1.D0.x.x.x.x)
I2C.end();
I2C.end(1);

}


36 changes: 36 additions & 0 deletions Sensors/MMA8451.c
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;
}


41 changes: 41 additions & 0 deletions Sensors/MMA8451.h
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
38 changes: 38 additions & 0 deletions Sensors/PCF8574.c
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;
}


45 changes: 45 additions & 0 deletions Sensors/PCF8574.h
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

0 comments on commit e9e92c6

Please sign in to comment.