Ben Willems / Mbed 2 deprecated MLX90418_I2C_master_bwi

Dependencies:   mbed

Revision:
16:a0bfe33f8a4a
Parent:
15:83bbc18cccbc
Child:
17:5b17c9dc85b2
--- a/main.cpp	Wed May 12 10:09:04 2021 +0000
+++ b/main.cpp	Fri May 21 12:42:56 2021 +0000
@@ -1,10 +1,18 @@
 #include "mbed.h"
 #include "main_init.h"
 #include "i2c_mbed_fpga.h"
+#include "uart_mbed.h"
 
+#define RAM_END_ADDR 0x4B
+
+#define CLIM_LEVEL 0x1F
+// I_LIM (A) = 4A * CLIM_LEVEL/127
 
 /* Main function */
 int main() {
+    char i2cBuffer[3];
+    char i2cTestPassFlag = 0;
+    char i2cRamDumpFlag = 0;
     
     /*init funcitons*/
     i2c_mbed_fpga i2c;
@@ -13,8 +21,8 @@
     /*control codes*/
       wait_ms(2000);   /* keep FPGA in reset for 5s, to let motor stop*/
       enbale_fpga();   /* enable FPGA */ 
-      wait_ms(45);      
-      i2c.i2c_config_mode_entry();  /*send password 0xd0d0*/
+      wait_ms(40);      
+      i2c.i2c_config_mode_entry(); 
       wait_ms(1);
       i2c.i2c_clear_spd_ctrl();
       wait_ms(1);
@@ -26,7 +34,7 @@
       wait_ms(1);
       i2c.i2c_set_50k_pwm(1);    
       wait_ms(1);        
-      i2c.i2c_set_position_pulse_width(2,2); /*unsigned int mantisaa_2b, unsigned int exponent_3b*/
+      i2c.i2c_set_position_pulse_width(2,5); /*unsigned int mantisaa_2b, unsigned int exponent_3b*/
       wait_ms(1);
 //    i2c.i2c_set_position_duty(3);
 //    wait_ms(10);
@@ -54,9 +62,49 @@
       wait_ms(1);
       i2c.i2c_set_ehp_reg_gain(0);
       wait_ms(1);
+      i2c.i2c_set_clim_start_up(CLIM_LEVEL);
+      wait_ms(1);
+      i2c.i2c_set_clim_brake(CLIM_LEVEL);
+      wait_ms(1);
+      i2c.i2c_set_clim_run_time(CLIM_LEVEL);
+      wait_ms(1);
       i2c.i2c_skip_app_copy();
       wait_ms(1);
-      led4 = i2c.i2c_soft_reset();  /*send password 0xcafe*/
+      
+      if(i2cRamDumpFlag == 1){
+      /*dump calibration data start*/
+        i2c.i2c_mlx_mode_entry();
+        wait_ms(1);
+        *(i2cBuffer+0) = (char)(I2C_STATUS)& 0xff;
+        i2c.i2c_word_read(i2cBuffer);
+        uart_print(i2cBuffer);
+        
+        if( i2cBuffer[2] == 0xC0 ){
+            uart_I2C_test_pass();
+            i2cTestPassFlag = 1;
+            led4 = 0;
+        }
+        else {
+            uart_I2C_test_fail();
+            i2cTestPassFlag = 0;
+            led4 = 1;
+        }
+        
+        if(i2cTestPassFlag == 1){
+            char i;
+            for(i=0;i<=RAM_END_ADDR;i++) {
+                *(i2cBuffer+0) = i;
+                i2c.i2c_word_read(i2cBuffer);
+                uart_print(i2cBuffer);
+                wait_ms(300);
+            }  
+            uart_ram_dump_finish();
+        }    
+      }
+      
+      
+      wait_ms(1);
+      i2c.i2c_soft_reset();  
       wait_ms(40);
       i2c.i2c_set_open_loop_duty(0xffff);