Ben Willems / Mbed 2 deprecated MLX90418_I2C_master_bwi

Dependencies:   mbed

Committer:
wuliqunyy
Date:
Wed May 12 10:09:04 2021 +0000
Revision:
15:83bbc18cccbc
Parent:
14:062850afdf38
Child:
16:a0bfe33f8a4a
New start up communication state machine working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wuliqunyy 0:fe3c7dde9771 1 #include "mbed.h"
wuliqunyy 5:daab0e0e67e2 2 #include "main_init.h"
wuliqunyy 6:019ab407ac3c 3 #include "i2c_mbed_fpga.h"
wuliqunyy 0:fe3c7dde9771 4
wuliqunyy 0:fe3c7dde9771 5
wuliqunyy 0:fe3c7dde9771 6 /* Main function */
wuliqunyy 0:fe3c7dde9771 7 int main() {
wuliqunyy 6:019ab407ac3c 8
wuliqunyy 6:019ab407ac3c 9 /*init funcitons*/
wuliqunyy 5:daab0e0e67e2 10 i2c_mbed_fpga i2c;
wuliqunyy 6:019ab407ac3c 11 main_init(); /*reset the FPGA!*/
wuliqunyy 3:557d5725b1bb 12
wuliqunyy 6:019ab407ac3c 13 /*control codes*/
wuliqunyy 14:062850afdf38 14 wait_ms(2000); /* keep FPGA in reset for 5s, to let motor stop*/
wuliqunyy 14:062850afdf38 15 enbale_fpga(); /* enable FPGA */
wuliqunyy 15:83bbc18cccbc 16 wait_ms(45);
wuliqunyy 15:83bbc18cccbc 17 i2c.i2c_config_mode_entry(); /*send password 0xd0d0*/
wuliqunyy 14:062850afdf38 18 wait_ms(1);
wuliqunyy 14:062850afdf38 19 i2c.i2c_clear_spd_ctrl();
wuliqunyy 14:062850afdf38 20 wait_ms(1);
wuliqunyy 15:83bbc18cccbc 21 i2c.i2c_set_comm_i_thres(0x0fff,1); //note, 0fff is -1 signed
wuliqunyy 14:062850afdf38 22 wait_ms(1);
wuliqunyy 14:062850afdf38 23 i2c.i2c_set_comm_di_thres(0,1);
wuliqunyy 14:062850afdf38 24 wait_ms(1);
wuliqunyy 14:062850afdf38 25 i2c.i2c_set_fall_time_blank(4);
wuliqunyy 14:062850afdf38 26 wait_ms(1);
wuliqunyy 13:1faffc2dc651 27 i2c.i2c_set_50k_pwm(1);
wuliqunyy 14:062850afdf38 28 wait_ms(1);
wuliqunyy 14:062850afdf38 29 i2c.i2c_set_position_pulse_width(2,2); /*unsigned int mantisaa_2b, unsigned int exponent_3b*/
wuliqunyy 14:062850afdf38 30 wait_ms(1);
wuliqunyy 12:9f8c7f4da5f6 31 // i2c.i2c_set_position_duty(3);
wuliqunyy 12:9f8c7f4da5f6 32 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 33 // i2c.i2c_set_position_anti_cog(0);
wuliqunyy 12:9f8c7f4da5f6 34 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 35 // i2c.i2c_set_start_up_duty(3);
wuliqunyy 12:9f8c7f4da5f6 36 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 37 i2c.i2c_set_start_up_pulse_width(3,5); /*(unsigned int mantisaa_3b, unsigned int exponent_3b*/
wuliqunyy 14:062850afdf38 38 wait_ms(1);
wuliqunyy 12:9f8c7f4da5f6 39 // i2c.i2c_set_start_up_num_comm(3);
wuliqunyy 12:9f8c7f4da5f6 40 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 41 // //led4 = i2c.i2c_set_soft_start_up(1, 1, 0, 1, 1);
wuliqunyy 12:9f8c7f4da5f6 42 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 43 // i2c.i2c_clear_spd_ctrl();
wuliqunyy 14:062850afdf38 44 wait_ms(1);
wuliqunyy 14:062850afdf38 45 i2c.i2c_set_loop_mode(0);
wuliqunyy 14:062850afdf38 46 wait_ms(1);
wuliqunyy 14:062850afdf38 47 i2c.i2c_set_curve_type(3);
wuliqunyy 14:062850afdf38 48 wait_ms(1);
wuliqunyy 14:062850afdf38 49 i2c.i2c_set_dc_ini(2);
wuliqunyy 14:062850afdf38 50 wait_ms(1);
wuliqunyy 14:062850afdf38 51 i2c.i2c_set_dc_sr(0);
wuliqunyy 14:062850afdf38 52 wait_ms(1);
wuliqunyy 12:9f8c7f4da5f6 53 i2c.i2c_set_rough_gain(0);
wuliqunyy 14:062850afdf38 54 wait_ms(1);
wuliqunyy 14:062850afdf38 55 i2c.i2c_set_ehp_reg_gain(0);
wuliqunyy 14:062850afdf38 56 wait_ms(1);
wuliqunyy 15:83bbc18cccbc 57 i2c.i2c_skip_app_copy();
wuliqunyy 15:83bbc18cccbc 58 wait_ms(1);
wuliqunyy 15:83bbc18cccbc 59 led4 = i2c.i2c_soft_reset(); /*send password 0xcafe*/
wuliqunyy 15:83bbc18cccbc 60 wait_ms(40);
wuliqunyy 15:83bbc18cccbc 61 i2c.i2c_set_open_loop_duty(0xffff);
wuliqunyy 6:019ab407ac3c 62
wuliqunyy 6:019ab407ac3c 63 /*enter infinite loop, motor should be running*/
wuliqunyy 5:daab0e0e67e2 64 while (1) {}
wuliqunyy 0:fe3c7dde9771 65
wuliqunyy 0:fe3c7dde9771 66 }