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.
main.cpp
00001 #include "mbed.h" 00002 00003 #define MLX90614_ADDR (0x5A) // Slave address 00004 #define MLX90614_TOBJ (0x07) // Object temperature register 00005 00006 //~~~~~~~~~~~~~~~~~~~~~~~~~~~GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00007 //~~~structure~~~// 00008 DigitalOut led(D13); //link leg 00009 00010 //~~~Sensor_I2C~~~// 00011 I2C i2c(D14, D15); //I2C reg(SDA, SCL) 00012 00013 //~~~Serial~~~// 00014 Serial pc(D1, D0); //Serial reg 00015 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00016 00017 00018 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00019 //~~~globle~~~// 00020 Ticker TT; //call a timer 00021 00022 //~~~Sensor_I2C~~~// 00023 char data_write[1]; //buff for write 00024 char data_read [3]; //buff for read 00025 short Buff = 0x00; 00026 float TOBJ = 0.0; 00027 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00028 00029 00030 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00031 void init_IO(); //initialize IO state 00032 void init_TIMER(); //set TT_main{} rate 00033 void TT_main(); //timebase function rated by TT 00034 void read_MLX(); //read MLX data give raw data 00035 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00036 00037 00038 //~~~~~~~~~~~~~~~~~~~~~~~~~~~main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00039 int main() 00040 { 00041 init_IO(); //initialized value and IRQ(Interrupt request) 00042 init_TIMER(); //start TT_main 00043 00044 while(1) { //main() loop 00045 } 00046 00047 } 00048 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00049 00050 00051 //~~~~~~~~~~~~~~~~~~~~~~~~~~~init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00052 void init_IO(void) //initialize 00053 { 00054 led = 0; 00055 pc.baud(9600); //set baud rate 00056 i2c.frequency(100000); //100kHz 00057 // NVIC_SetPriority(I2C1_ER_IRQn, 0); //!!!!!!!!!!!!!!!!!!!!!!!!! 00058 // NVIC_SetPriority(I2C1_EV_IRQn, 0); //!!!!!!!!!!!!!!!!!!!!!!!!! 00059 NVIC_SetPriority(TIM5_IRQn, 51); //!!!!!!!!!!!!!!!!!!!!!!!!! 00060 } 00061 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00062 00063 00064 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00065 void init_TIMER() //set TT_main{} rate 00066 { 00067 TT.attach_us(&TT_main, 10000); //rate set to 100Hz 00068 } 00069 00070 void TT_main() //interrupt function by TT 00071 { 00072 read_MLX(); //update MLX data 00073 TOBJ = ((float)Buff * 0.02f) - 273.0f; 00074 printf("%.2f\n",TOBJ); 00075 } 00076 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// 00077 00078 00079 00080 //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓read_IMU funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓// 00081 void read_MLX(void) //read MLX data give raw data 00082 { 00083 //TOBJ 00084 data_write[0] = MLX90614_TOBJ; //TOBJ address to buff 00085 i2c.write( MLX90614_ADDR<<1 | 0x00, data_write, 1, 1); //command to RAM access 00086 i2c.read ( MLX90614_ADDR<<1 | 0x01, data_read , 3, 0); //read callback 00087 Buff = data_read[1] << 8 |data_read[0]; 00088 } 00089 //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of read_IMU funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
Generated on Sun Aug 7 2022 11:47:28 by
1.7.2