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.
Dependents: NucleoMGC3130 i2c_master
MGC3130.cpp
00001 #include "MGC3130.h" 00002 00003 MGC3130::MGC3130(PinName sda, PinName scl, PinName EI0, bool IS2) 00004 :TS_Line(EI0), _i2c_bus(sda,scl), msg(), sensor() 00005 { 00006 TS_Line.output(); 00007 TS_Line.write(1); 00008 _i2c_bus.frequency(FREQUENCY_FULL); 00009 00010 if (IS2) 00011 _addr = 0x86; 00012 else 00013 _addr = 0x84; 00014 } 00015 00016 GestICMsg * MGC3130::readMsg() 00017 { 00018 TS_Line.input(); 00019 if (TS_Line.read() == 0) 00020 return NULL; 00021 00022 msg.rewind(); 00023 00024 TS_Line.output(); 00025 TS_Line.write(0); 00026 00027 _i2c_bus.start(); 00028 _i2c_bus.write(_addr | 0x01); 00029 00030 int size = _i2c_bus.read(1); 00031 msg.set(size); 00032 00033 for (int i = 1; i < size - 1; i++) 00034 msg.set(_i2c_bus.read(1)); 00035 00036 msg.set(_i2c_bus.read(0)); 00037 00038 _i2c_bus.stop(); 00039 TS_Line.write(1); 00040 wait_us(200); 00041 return &msg; 00042 } 00043 00044 SensorData * MGC3130::readSensorData() 00045 { 00046 if (readMsg() != NULL && sensor.convert(&msg)) 00047 return &sensor; 00048 else return NULL; 00049 } 00050 00051 int MGC3130::setRuntimeParameter(Parameter * para) 00052 { 00053 _i2c_bus.start(); 00054 _i2c_bus.write(_addr); 00055 _i2c_bus.write(0x10); 00056 _i2c_bus.write(0x00); 00057 _i2c_bus.write(0x00); 00058 _i2c_bus.write(0xA2); 00059 00060 for (int i =0; i < Parameter::Length; i++) 00061 _i2c_bus.write(para->gets()[i]); 00062 00063 _i2c_bus.stop(); 00064 00065 while (!(readMsg() != NULL || msg.getID() == GestICMsg::System_Status)) 00066 setRuntimeParameter(para); 00067 00068 return msg.get(6) | (msg.get(7) << 8); 00069 }
Generated on Fri Jul 15 2022 02:54:57 by
