Skip to content

Commit 60a6d30

Browse files
Added registers to project; started functions
Started the basic layout of the functions needed, along with adding all the registers to use.
1 parent a325d2e commit 60a6d30

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

src/SparkFun_TMAG5273.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,21 @@ bool TMAG5273::begin(uint8_t sensorAddress, TwoWire &wirePort)
5858
}
5959

6060

61+
/* GET ADDRESS
62+
This function returns the address of the device once
63+
called upon. This address can only be 0x22.
64+
*/
65+
uint8_t TMP117::getAddress()
66+
{
67+
return _deviceAddress;
68+
}
69+
70+
71+
/* READ TEMPERATURE
72+
- Enable temperature bit from T_CONFIG Register
73+
- Read temperature back
74+
*/
75+
float TMAG5273::readTemperature(void)
76+
{
77+
78+
}

src/SparkFun_TMAG5273.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,37 @@ local, and you've found our code helpful, please buy us a round!
1717
Distributed as-is; no warranty is given.
1818
******************************************************************************/
1919

20+
#ifndef __SparkFun_TMAG5273_H__
21+
#define __SparkFun_TMAG5273_H__
22+
23+
#include <Wire.h>
24+
#include <Arduino.h>
25+
#include "SparkFun_TMAG5273_Registers.h"
26+
27+
#define DEVICE_ID_VALUE 0x22 // Value found in the device ID register
28+
29+
30+
class TMAG5273
31+
{
32+
public:
33+
TMAG5273(); // Constructor
34+
35+
bool begin(uint8_t sensorAddress = 0x48, TwoWire &wirePort = Wire); // Checks for ACK over I2C, and sets the device ID of the TMAG and chooses the wire port
36+
uint8_t getAddress(); // Returns the address of the device
37+
38+
float readTemperature(void); // Returns temperature of device
39+
uint8_t readMagField(float* Bx, float* By, float* Bz); // Returns the magnetic field of the device - precise up to +/-1mT
40+
41+
42+
43+
44+
private:
45+
TwoWire *_i2cPort = NULL;
46+
uint8_t _deviceAddress;
47+
48+
uint16_t readRegister(uint8_t reg); // Reads 2 register bytes from sensor
49+
void writeRegister(uint8_t reg, uint16_t data); // Wires single byte of data to the sensor
50+
51+
}
52+
53+
#endif

src/SparkFun_TMAG5273_Registers.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,39 @@ local, and you've found our code helpful, please buy us a round!
1717
Distributed as-is; no warranty is given.
1818
******************************************************************************/
1919

20+
#ifndef __SparkFun_TMAG5273_Registers_H__
21+
#define __SparkFun_TMAG5273_Registers_H__
22+
23+
enum TMAG5273_Register
24+
{
25+
TMAG5273_DEVICE_CONFIG_1 = 0X00,
26+
TMAG5273_DEVICE_CONFIG_2 = 0X01,
27+
TMAG5273_SENSOR_CONFIG_1 = 0X02,
28+
TMAG5273_SENSOR_CONFIG_2 = 0X03,
29+
TMAG5273_X_THR_CONFIG = 0X04,
30+
TMAG5273_Y_THR_CONFIG = 0X05,
31+
TMAG5273_Z_THR_CONFIG = 0X06,
32+
TMAG5273_T_CONFIG = 0X07,
33+
TMAG5273_INT_CONFIG_1 = 0X08,
34+
TMAG5273_MAG_GAIN_CONFIG = 0X09,
35+
TMAG5273_MAG_OFFSET_CONFIG_1 = 0X0A,
36+
TMAG5273_MAG_OFFSET_CONFIG_2 = 0X0B,
37+
TMAG5273_I2C_ADDRESS = 0X0C,
38+
TMAG5273_DEVICE_ID = 0X0D,
39+
TMAG5273_MANUFACTURER_ID_LSB = 0X0E,
40+
TMAG5273_MANUFACTURER_ID_MSB = 0X0F,
41+
TMAG5273_T_MSB_RESULT = 0X10,
42+
TMAG5273_T_LSB_RESULT = 0X11,
43+
TMAG5273_X_MSB_RESULT = 0X12,
44+
TMAG5273_X_LSB_RESULT = 0X13
45+
TMAG5273_Y_MSB_RESULT = 0X14,
46+
TMAG5273_Y_LSB_RESULT = 0X15,
47+
TMAG5273_Z_MSB_RESULT = 0X16,
48+
TMAG5273_Z_LSB_RESULT = 0X17,
49+
TMAG5273_CONV_STATUS = 0X18,
50+
TMAG5273_ANGLE_RESULT_MSB = 0X19,
51+
TMAG5273_ANGLE_RESULT_LSB = 0X1A,
52+
TMAG5273_MAGNITUDE_RESULT = 0X1B
53+
};
54+
55+
#endif

0 commit comments

Comments
 (0)