SRK Version of mDot LoRa_Sensormode_SRK
Dependencies: libmDot mbed-rtos mbed
Fork of mDot_LoRa_Sensornode by
I2C_RT.cpp
00001 /* 00002 * I2C_RT.cpp 00003 * 00004 * Created on: 19.05.2016 00005 * Author: Adrian 00006 */ 00007 00008 #include "I2C_RT.h " 00009 00010 I2C_RT::I2C_RT(){ 00011 00012 } 00013 00014 I2C_RT::~I2C_RT() { 00015 00016 } 00017 00018 00019 void I2C_RT::read_RT(uint8_t address,uint16_t reg,bool isTwoBytes,uint8_t*data,uint8_t dataLenght){ 00020 00021 mbed::I2C i2c(I2C_SDA,I2C_SCL); 00022 i2c.frequency(100000); 00023 00024 // Some Cast 00025 //TODO find a more proper solution 00026 int sensorAddress = (int)address; 00027 char dataToWrite[2] = {(char)(reg>>8),(char)reg}; 00028 char* readData = (char*) data; 00029 00030 if(isTwoBytes){ 00031 i2c.write(sensorAddress,dataToWrite,dataLenght); 00032 } 00033 else{ 00034 i2c.write(sensorAddress,&dataToWrite[1],dataLenght); 00035 } 00036 00037 i2c.read(address,readData,dataLenght); 00038 00039 } 00040 void I2C_RT::write_RT(uint8_t address,uint16_t reg,bool isTwoBytes,uint8_t*data,uint8_t dataLenght){ 00041 mbed::I2C i2c(I2C_SDA,I2C_SCL); 00042 i2c.frequency(100000); 00043 00044 // Some Cast 00045 //TODO find a more proper solution 00046 int sensorAddress = (int) address; 00047 char dataToWrite[3] = {(char)(reg>>8),(char)reg,(char)*data}; 00048 00049 if(isTwoBytes){ 00050 i2c.write(sensorAddress,&dataToWrite[0],3); 00051 } 00052 else{ 00053 i2c.write(sensorAddress,&dataToWrite[1],2); 00054 } 00055 00056 } 00057
Generated on Wed Jul 13 2022 09:23:47 by 1.7.2