Simple tiltmeter using accelerometer

Dependencies:   mbed C12832

Committer:
chtjhai
Date:
Sat Nov 23 04:58:09 2019 +0000
Revision:
0:7d6134e052e0
Simple tiltmeter using accelerometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chtjhai 0:7d6134e052e0 1 /**
chtjhai 0:7d6134e052e0 2 * File : ENGO333_I2C.h
chtjhai 0:7d6134e052e0 3 * Created by : Chandra Tjhai
chtjhai 0:7d6134e052e0 4 * Created on : September 10, 2016
chtjhai 0:7d6134e052e0 5 *
chtjhai 0:7d6134e052e0 6 * Description :
chtjhai 0:7d6134e052e0 7 * This file contains a class to handle I2C bus operation for ENGO 333.
chtjhai 0:7d6134e052e0 8 */
chtjhai 0:7d6134e052e0 9
chtjhai 0:7d6134e052e0 10 #ifndef ENGO333_I2C_H
chtjhai 0:7d6134e052e0 11 #define ENGO333_I2C_H
chtjhai 0:7d6134e052e0 12
chtjhai 0:7d6134e052e0 13 #include "mbed.h"
chtjhai 0:7d6134e052e0 14
chtjhai 0:7d6134e052e0 15 /**
chtjhai 0:7d6134e052e0 16 * Class
chtjhai 0:7d6134e052e0 17 * A class to handle I2C read/write operation
chtjhai 0:7d6134e052e0 18 */
chtjhai 0:7d6134e052e0 19 class ENGO333_I2C
chtjhai 0:7d6134e052e0 20 {
chtjhai 0:7d6134e052e0 21 private:
chtjhai 0:7d6134e052e0 22 I2C i2c; // Object for handling I2C bus operations
chtjhai 0:7d6134e052e0 23
chtjhai 0:7d6134e052e0 24 public:
chtjhai 0:7d6134e052e0 25 /**
chtjhai 0:7d6134e052e0 26 * Constructor
chtjhai 0:7d6134e052e0 27 *
chtjhai 0:7d6134e052e0 28 * Input
chtjhai 0:7d6134e052e0 29 * sda = SDA or I2C serial data pin
chtjhai 0:7d6134e052e0 30 * scl = SCL or I2C serial clock pin
chtjhai 0:7d6134e052e0 31 */
chtjhai 0:7d6134e052e0 32 ENGO333_I2C(PinName sda, PinName scl);
chtjhai 0:7d6134e052e0 33
chtjhai 0:7d6134e052e0 34 /**
chtjhai 0:7d6134e052e0 35 * Destructor
chtjhai 0:7d6134e052e0 36 */
chtjhai 0:7d6134e052e0 37 ~ENGO333_I2C();
chtjhai 0:7d6134e052e0 38
chtjhai 0:7d6134e052e0 39 /**
chtjhai 0:7d6134e052e0 40 * Function :
chtjhai 0:7d6134e052e0 41 * Set I2C bus frequency
chtjhai 0:7d6134e052e0 42 *
chtjhai 0:7d6134e052e0 43 * Input :
chtjhai 0:7d6134e052e0 44 * freq = desired frequency in Hz
chtjhai 0:7d6134e052e0 45 */
chtjhai 0:7d6134e052e0 46 void setSpeed(int freq);
chtjhai 0:7d6134e052e0 47
chtjhai 0:7d6134e052e0 48 /**
chtjhai 0:7d6134e052e0 49 * Function :
chtjhai 0:7d6134e052e0 50 * Write one byte data into device's register
chtjhai 0:7d6134e052e0 51 *
chtjhai 0:7d6134e052e0 52 * Input :
chtjhai 0:7d6134e052e0 53 * deviceAddress = Device's I2C address
chtjhai 0:7d6134e052e0 54 * registerAddress = Device's register address to be written on
chtjhai 0:7d6134e052e0 55 * value = Value to be written on device's register address
chtjhai 0:7d6134e052e0 56 */
chtjhai 0:7d6134e052e0 57 void writeOneByte(char deviceAddress, char registerAddress, char value);
chtjhai 0:7d6134e052e0 58
chtjhai 0:7d6134e052e0 59 /**
chtjhai 0:7d6134e052e0 60 * Function :
chtjhai 0:7d6134e052e0 61 * Read one byte from device's register address
chtjhai 0:7d6134e052e0 62 *
chtjhai 0:7d6134e052e0 63 * Input :
chtjhai 0:7d6134e052e0 64 * deviceAddress = Device's I2C address
chtjhai 0:7d6134e052e0 65 * registerAddress = Device's register address to be read
chtjhai 0:7d6134e052e0 66 *
chtjhai 0:7d6134e052e0 67 * Return :
chtjhai 0:7d6134e052e0 68 * One byte data read from device's register
chtjhai 0:7d6134e052e0 69 */
chtjhai 0:7d6134e052e0 70 char readOneByte(char deviceAddress, char registerAddress);
chtjhai 0:7d6134e052e0 71
chtjhai 0:7d6134e052e0 72 /**
chtjhai 0:7d6134e052e0 73 * Function :
chtjhai 0:7d6134e052e0 74 * Read multiple bytes from device's register address
chtjhai 0:7d6134e052e0 75 *
chtjhai 0:7d6134e052e0 76 * Input :
chtjhai 0:7d6134e052e0 77 * deviceAddress = Device's I2C address
chtjhai 0:7d6134e052e0 78 * registerAddress = Device's register address to be read
chtjhai 0:7d6134e052e0 79 * value = Array of data to store values read from device's register
chtjhai 0:7d6134e052e0 80 */
chtjhai 0:7d6134e052e0 81 void readBytes(char deviceAddress, char registerAddress, char* value, int length);
chtjhai 0:7d6134e052e0 82 };
chtjhai 0:7d6134e052e0 83
chtjhai 0:7d6134e052e0 84 #endif
chtjhai 0:7d6134e052e0 85