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: MtSense07
Fork of MtConnect04S_MtSense07 by
main.cpp
00001 /* Copyright (c) 2016 MtM Technology Corporation, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 #include "mbed.h" 00019 #include "AK9750.h" 00020 #include "AK09912.h" 00021 #include "AK09970.h" 00022 #include "config.h" 00023 00024 I2C i2c(p3, p2); 00025 00026 #ifdef NRF52 00027 Serial pc(p18, p16); 00028 DigitalOut reset_sensor(p24, 1); // Reset pin for AK09970 (Low active) 00029 AK9750 ak9750(i2c, p5); 00030 #else 00031 Serial pc(p15, p16); 00032 DigitalOut reset_sensor(p4, 1); // Reset pin for AK09970 (Low active) 00033 AK9750 ak9750(i2c, p0); 00034 #endif 00035 00036 AK09912 ak09912(i2c); 00037 AK09970 ak09970(i2c); 00038 00039 volatile bool isIntEvent = false; 00040 static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE); 00041 int32_t count = 0; 00042 00043 //============================================================================== 00044 static void IntEventCallback() { 00045 isIntEvent = true; 00046 } 00047 void readSensorCallback() { 00048 #if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM) 00049 AK9750::Data ak9750_data; 00050 AK09912::Data ak09912_data; 00051 AK09970::Data ak09970_data; 00052 int32_t triggered_area; 00053 ak9750.GetData(&ak9750_data); 00054 triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data); 00055 pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n", 00056 ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area); 00057 00058 ak09912.GetData(&ak09912_data); 00059 pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n", 00060 ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t); 00061 00062 ak09970.GetData(&ak09970_data); 00063 pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n", 00064 ak09970_data.x, ak09970_data.y, ak09970_data.z); 00065 00066 pc.printf("\n"); 00067 #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_APP) 00068 AK9750::Data ak9750_data; 00069 ak9750.GetData(&ak9750_data); 00070 pc.printf(" 3:%d,%d,%d,%d,%d,\r", count, (int32_t)ak9750_data.ir1, (int32_t)ak9750_data.ir2, (int32_t)ak9750_data.ir3, (int32_t)ak9750_data.ir4); 00071 count++; 00072 00073 #elif (CONFIG_RUN_MODE == RUN_COMPASS_AK09912_APP) 00074 AK09912::Data ak09912_data; 00075 ak09912.GetData(&ak09912_data); 00076 pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09912_data.x, (int32_t)ak09912_data.y, (int32_t)ak09912_data.z); 00077 count++; 00078 00079 #elif (CONFIG_RUN_MODE == RUN_MAGNETIC_AK09970_APP) 00080 AK09970::Data ak09970_data; 00081 ak09970.GetData(&ak09970_data); 00082 pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09970_data.x, (int32_t)ak09970_data.y, (int32_t)ak09970_data.z); 00083 count++; 00084 #endif 00085 } 00086 //============================================================================== 00087 int main() { 00088 /* Disable the hardware flow control of Serial, then show the mbed version */ 00089 pc.set_flow_control(SerialBase::Disabled); 00090 pc.baud(CONFIG_BAUDRATE); 00091 pc.printf("\n"); 00092 pc.printf("mbed version(%d.%d.%d)\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); 00093 pc.printf("\n"); 00094 00095 /* Reset sensor */ 00096 reset_sensor = 1; 00097 wait_ms(10); 00098 reset_sensor = 0; 00099 wait_ms(10); 00100 reset_sensor = 1; 00101 wait_ms(10); 00102 00103 /* Config device and check device ID */ 00104 uint8_t id; 00105 00106 ak9750.ConfigDevice(); 00107 ak9750.GetDeviceID(&id); 00108 pc.printf("AK9750_DEVICE_ID(0x%02X)\n", id); 00109 if(id != ak9750.DEVICE_ID){ 00110 pc.printf("Read Device ID fail !\n"); 00111 while(1); 00112 } 00113 00114 ak09912.ConfigDevice(); 00115 ak09912.GetDeviceID(&id); 00116 pc.printf("AK09912_DEVICE_ID(0x%02X)\n", id); 00117 if(id != ak09912.DEVICE_ID){ 00118 pc.printf("Read Device ID fail !\n"); 00119 while(1); 00120 } 00121 00122 ak09970.ConfigDevice(); 00123 ak09970.GetDeviceID(&id); 00124 pc.printf("AK09970_DEVICE_ID(0x%02X)\n", id); 00125 if(id != ak09970.DEVICE_ID){ 00126 pc.printf("Read Device ID fail !\n"); 00127 while(1); 00128 } 00129 00130 00131 /* Main loop */ 00132 #if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM) 00133 eventQueue.call_every(200, readSensorCallback); 00134 eventQueue.dispatch_forever(); 00135 00136 #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_APP) 00137 eventQueue.call_every(200, readASensorCallback); 00138 eventQueue.dispatch_forever(); 00139 00140 #elif (CONFIG_RUN_MODE == RUN_COMPASS_AK09912_APP) 00141 eventQueue.call_every(200, readASensorCallback); 00142 eventQueue.dispatch_forever(); 00143 00144 #elif (CONFIG_RUN_MODE == RUN_MAGNETIC_AK09970_APP) 00145 eventQueue.call_every(200, readASensorCallback); 00146 eventQueue.dispatch_forever(); 00147 00148 #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_INT_COM) 00149 // Enable interrupt sources and set callback function 00150 ak9750.SetIntEvent(AK9750::INT_DR, &IntEventCallback); 00151 00152 while (1) { 00153 /* If any interrupt occurred */ 00154 if (isIntEvent) { 00155 /* Read interrupt status */ 00156 uint8_t status = ak9750.GetIntStatus(); 00157 if (status & AK9750::INT_DR) { 00158 pc.printf("INT_DR\n"); 00159 /* Read data */ 00160 AK9750::Data data; 00161 ak9750.GetData(&data); 00162 pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA)\n", data.ir1, data.ir2, data.ir3, data.ir4); 00163 } 00164 if (status & AK9750::INT_IR24L) pc.printf("INT_IR24L\n"); 00165 if (status & AK9750::INT_IR24H) pc.printf("INT_IR24H\n"); 00166 if (status & AK9750::INT_IR13L) pc.printf("INT_IR13L\n"); 00167 if (status & AK9750::INT_IR13H) pc.printf("INT_IR13H\n"); 00168 isIntEvent = false; 00169 } 00170 } 00171 #else 00172 #errror "Config run mode ...FAIL" 00173 #endif 00174 }
Generated on Tue Jul 19 2022 08:23:21 by
1.7.2
