51 52 with same code

Dependencies:   MtSense07

Fork of MtConnect04S_MtSense07 by MtM+

Committer:
bcc6
Date:
Thu Jan 26 03:54:58 2017 +0000
Revision:
0:418880413158
Child:
1:40c18f027e6c
Utilize mbed os 5. ; Display sensor value through the serial, refresh every second. ; Note: Default serial pins is conflict between MtAid01-mbed and MtSense07 board, so MtAid01-mbed is needed to rework and jump-wire.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcc6 0:418880413158 1 /* Copyright (c) 2016 MtM Technology Corporation, MIT License
bcc6 0:418880413158 2 *
bcc6 0:418880413158 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bcc6 0:418880413158 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bcc6 0:418880413158 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bcc6 0:418880413158 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bcc6 0:418880413158 7 * furnished to do so, subject to the following conditions:
bcc6 0:418880413158 8 *
bcc6 0:418880413158 9 * The above copyright notice and this permission notice shall be included in all copies or
bcc6 0:418880413158 10 * substantial portions of the Software.
bcc6 0:418880413158 11 *
bcc6 0:418880413158 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bcc6 0:418880413158 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bcc6 0:418880413158 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bcc6 0:418880413158 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bcc6 0:418880413158 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bcc6 0:418880413158 17 */
bcc6 0:418880413158 18 #include "mbed.h"
bcc6 0:418880413158 19 #include "AK9750.h"
bcc6 0:418880413158 20 #include "AK09912.h"
bcc6 0:418880413158 21 #include "AK09970.h"
bcc6 0:418880413158 22
bcc6 0:418880413158 23 Serial pc(p15, p16);
bcc6 0:418880413158 24
bcc6 0:418880413158 25 DigitalOut reset_sensor(p4, 1); // Reset pin for AK09970 (Low active)
bcc6 0:418880413158 26 I2C i2c(p3, p2);
bcc6 0:418880413158 27 AK9750 ak9750(i2c);
bcc6 0:418880413158 28 AK09912 ak09912(i2c);
bcc6 0:418880413158 29 AK09970 ak09970(i2c);
bcc6 0:418880413158 30
bcc6 0:418880413158 31 int main() {
bcc6 0:418880413158 32 /* Disable the hardware flow control of Serial, then show the mbed version */
bcc6 0:418880413158 33 pc.set_flow_control(SerialBase::Disabled);
bcc6 0:418880413158 34 pc.printf("\n");
bcc6 0:418880413158 35 pc.printf("mbed version(%d.%d.%d)\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
bcc6 0:418880413158 36 pc.printf("\n");
bcc6 0:418880413158 37
bcc6 0:418880413158 38 /* Reset sensor */
bcc6 0:418880413158 39 reset_sensor = 1;
bcc6 0:418880413158 40 wait_ms(10);
bcc6 0:418880413158 41 reset_sensor = 0;
bcc6 0:418880413158 42 wait_ms(10);
bcc6 0:418880413158 43 reset_sensor = 1;
bcc6 0:418880413158 44 wait_ms(10);
bcc6 0:418880413158 45
bcc6 0:418880413158 46 /* Config device and check device ID */
bcc6 0:418880413158 47 uint8_t id;
bcc6 0:418880413158 48
bcc6 0:418880413158 49 ak9750.ConfigDevice();
bcc6 0:418880413158 50 ak9750.GetDeviceID(&id);
bcc6 0:418880413158 51 pc.printf("AK9750_DEVICE_ID(0x%02X)\n", id);
bcc6 0:418880413158 52 if(id != ak9750.DEVICE_ID){
bcc6 0:418880413158 53 pc.printf("Read Device ID fail !\n");
bcc6 0:418880413158 54 while(1);
bcc6 0:418880413158 55 }
bcc6 0:418880413158 56
bcc6 0:418880413158 57 ak09912.ConfigDevice();
bcc6 0:418880413158 58 ak09912.GetDeviceID(&id);
bcc6 0:418880413158 59 pc.printf("AK09912_DEVICE_ID(0x%02X)\n", id);
bcc6 0:418880413158 60 if(id != ak09912.DEVICE_ID){
bcc6 0:418880413158 61 pc.printf("Read Device ID fail !\n");
bcc6 0:418880413158 62 while(1);
bcc6 0:418880413158 63 }
bcc6 0:418880413158 64
bcc6 0:418880413158 65 ak09970.ConfigDevice();
bcc6 0:418880413158 66 ak09970.GetDeviceID(&id);
bcc6 0:418880413158 67 pc.printf("AK09970_DEVICE_ID(0x%02X)\n", id);
bcc6 0:418880413158 68 if(id != ak09970.DEVICE_ID){
bcc6 0:418880413158 69 pc.printf("Read Device ID fail !\n");
bcc6 0:418880413158 70 while(1);
bcc6 0:418880413158 71 }
bcc6 0:418880413158 72
bcc6 0:418880413158 73 /* Main loop */
bcc6 0:418880413158 74 AK9750::Data ak9750_data;
bcc6 0:418880413158 75 AK09912::Data ak09912_data;
bcc6 0:418880413158 76 AK09970::Data ak09970_data;
bcc6 0:418880413158 77 int32_t triggered_area;
bcc6 0:418880413158 78
bcc6 0:418880413158 79 while (1) {
bcc6 0:418880413158 80 ak9750.GetData(&ak9750_data);
bcc6 0:418880413158 81 triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data);
bcc6 0:418880413158 82 pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n",
bcc6 0:418880413158 83 ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area);
bcc6 0:418880413158 84
bcc6 0:418880413158 85 ak09912.GetData(&ak09912_data);
bcc6 0:418880413158 86 pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n",
bcc6 0:418880413158 87 ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t);
bcc6 0:418880413158 88
bcc6 0:418880413158 89 ak09970.GetData(&ak09970_data);
bcc6 0:418880413158 90 pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n",
bcc6 0:418880413158 91 ak09970_data.x, ak09970_data.y, ak09970_data.z);
bcc6 0:418880413158 92
bcc6 0:418880413158 93 pc.printf("\n");
bcc6 0:418880413158 94 wait(1);
bcc6 0:418880413158 95 }
bcc6 0:418880413158 96 }