Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:f043a4a4ec8d
- Child:
- 1:68e3916ad434
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 01 10:03:37 2016 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include <I2C.h> + +#define LSM6DS0_ADDRESS_WRITE (0xD4) // Configuration Register_write +#define LSM6DS0_ADDRESS_READ (0xD5) + +I2C i2c(I2C_SDA,I2C_SCL); +Serial pc(SERIAL_TX, SERIAL_RX); + +int main() { + +} + +int setREG_I2C(char REG_ADDR_DATA[2]){ //argument to pass : address register and data to write in +i2c.start(); //send start bit +if ((i2c.write(LSM6DS0_ADDRESS_WRITE,REG_ADDR_DATA,2,0))!=0){ //ADDR+SUB+DATA+STOP, return 0 if ack + pc.printf("Error, not ack\n"); + return 0; + } else return 1; +} + + +char readREG_I2C(char REG_ADDR[1]){ //argument to pass : address register to read +char data_read[1]; +i2c.start(); //send start bit +if ((i2c.write(LSM6DS0_ADDRESS_WRITE,REG_ADDR,1,1))==0){ //ADDR+SUB, return 0 if ack + if((i2c.read(LSM6DS0_ADDRESS_READ,data_read,1,0))==0){} //ADDR+data+STOP, return 0 if ack + else{ + pc.printf("Error, not ack\n"); + } + } else{ + pc.printf("Error, not ack\n"); + } + return data_read[0]; +} \ No newline at end of file