CSSE4011_BLE_IMU IMU Seeed Tiny Ble
Dependencies: BLE_API_Tiny_BLE MPU6050-DMP-Seeed-Tiny-BLE mbed
mbed_i2c.c
- Committer:
- flywind
- Date:
- 2015-06-10
- Revision:
- 2:44bc61abdf33
File content as of revision 2:44bc61abdf33:
#include "i2c_api.h" static i2c_t mbed_i2c_object; void mbed_i2c_init(PinName sda, PinName scl) { i2c_init(&mbed_i2c_object, sda, scl); i2c_frequency(&mbed_i2c_object, 100000); } int mbed_i2c_write(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char const *data) { int i; slave_addr = slave_addr << 1; i2c_start(&mbed_i2c_object); i2c_byte_write(&mbed_i2c_object, slave_addr); i2c_byte_write(&mbed_i2c_object, reg_addr); for (i = 0; i < length; i++) { i2c_byte_write(&mbed_i2c_object, data[i]); } i2c_stop(&mbed_i2c_object); return 0; } int mbed_i2c_read(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char *data) { slave_addr = slave_addr << 1; i2c_write(&mbed_i2c_object, slave_addr, ®_addr, 1, 0); return (i2c_read(&mbed_i2c_object, slave_addr, data, length, 1) == length) ? 0 : 1; }