Ovidiu Cincheza
/
NucleoMGC3130
MGC3130 communication test
main.cpp@1:a6f1d535bbdb, 2015-10-13 (annotated)
- Committer:
- ovicin
- Date:
- Tue Oct 13 10:53:07 2015 +0000
- Revision:
- 1:a6f1d535bbdb
- Parent:
- 0:41f53df528da
first commit, not working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:41f53df528da | 1 | #include "mbed.h" |
ovicin | 1:a6f1d535bbdb | 2 | #include "MGC3130.h" |
ovicin | 1:a6f1d535bbdb | 3 | |
bcostm | 0:41f53df528da | 4 | DigitalOut myled(LED1); |
bcostm | 0:41f53df528da | 5 | |
bcostm | 0:41f53df528da | 6 | Serial pc(SERIAL_TX, SERIAL_RX); |
bcostm | 0:41f53df528da | 7 | |
ovicin | 1:a6f1d535bbdb | 8 | /** |
ovicin | 1:a6f1d535bbdb | 9 | * IS2 is available for address selection and enables the user to connect up to two MGC3X30 devices on the same bus without address conflict. |
ovicin | 1:a6f1d535bbdb | 10 | * The MGC3X30 I2C addresses are 0x42 and 0x43. They are given as device addresses without the R/W bit. |
ovicin | 1:a6f1d535bbdb | 11 | * In addition, MGC3X30 requires a dedicated transfer status line (TS), which features a |
ovicin | 1:a6f1d535bbdb | 12 | * data transfer status function. The TS is used by both I2C Master and Slave to control |
ovicin | 1:a6f1d535bbdb | 13 | * the data flow. I2C SCL, I2C SDA and TS lines require an open-drain connection on |
ovicin | 1:a6f1d535bbdb | 14 | * MGC3X30 and the connected host controller. To function properly, I2C SCL and I2C |
ovicin | 1:a6f1d535bbdb | 15 | * SDA need to be pulled up to VCC with 1.8 kΩ resistors and the TS line needs to be |
ovicin | 1:a6f1d535bbdb | 16 | * pulled up to VCC with a 10 kΩ resistor. |
ovicin | 1:a6f1d535bbdb | 17 | * |
ovicin | 1:a6f1d535bbdb | 18 | * @param sda I2C sda signal |
ovicin | 1:a6f1d535bbdb | 19 | * @param scl I2C scl signal |
ovicin | 1:a6f1d535bbdb | 20 | * @param EI0 transfer status line |
ovicin | 1:a6f1d535bbdb | 21 | * @param IS2 High->true, Low->false |
ovicin | 1:a6f1d535bbdb | 22 | * |
ovicin | 1:a6f1d535bbdb | 23 | */ |
ovicin | 1:a6f1d535bbdb | 24 | |
ovicin | 1:a6f1d535bbdb | 25 | MGC3130 gestic(I2C_SDA, I2C_SCL, PB_1, false ); |
ovicin | 1:a6f1d535bbdb | 26 | |
ovicin | 1:a6f1d535bbdb | 27 | SensorData *data; |
ovicin | 1:a6f1d535bbdb | 28 | |
bcostm | 0:41f53df528da | 29 | |
bcostm | 0:41f53df528da | 30 | int main() |
bcostm | 0:41f53df528da | 31 | { |
bcostm | 0:41f53df528da | 32 | |
ovicin | 1:a6f1d535bbdb | 33 | pc.printf("Hello World !\r\n"); |
bcostm | 0:41f53df528da | 34 | |
bcostm | 0:41f53df528da | 35 | while (1) { |
ovicin | 1:a6f1d535bbdb | 36 | data = gestic.readSensorData(); |
ovicin | 1:a6f1d535bbdb | 37 | if (data == NULL){ |
ovicin | 1:a6f1d535bbdb | 38 | pc.printf("Data not avail\r\n"); |
ovicin | 1:a6f1d535bbdb | 39 | } |
ovicin | 1:a6f1d535bbdb | 40 | else{ |
ovicin | 1:a6f1d535bbdb | 41 | if (NULL != data->getxyzPosition()) |
ovicin | 1:a6f1d535bbdb | 42 | pc.printf("Got position data \r\n"); |
ovicin | 1:a6f1d535bbdb | 43 | } |
bcostm | 0:41f53df528da | 44 | |
bcostm | 0:41f53df528da | 45 | // Display result |
bcostm | 0:41f53df528da | 46 | myled = !myled; |
bcostm | 0:41f53df528da | 47 | wait(1.0); |
bcostm | 0:41f53df528da | 48 | } |
bcostm | 0:41f53df528da | 49 | |
bcostm | 0:41f53df528da | 50 | } |
bcostm | 0:41f53df528da | 51 |