Bavo Van Achte
/
MLX90418_I2C_master
Fork
main.cpp
- Committer:
- wuliqunyy
- Date:
- 2020-12-07
- Revision:
- 1:47cc6952e346
- Parent:
- 0:fe3c7dde9771
- Child:
- 2:9bdcd2c966de
File content as of revision 1:47cc6952e346:
#include "mbed.h" #include "i2c_mbed_fpga.h" //#include "serial_fsm.h" /*Digital outputs*/ DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); DigitalOut fpga_rstb(p21); //p21 of MBED is connectted to p4 of the FPGA CMOD for 90415FPGA_EVB2 /*Creat serial port to coummunicate with pc*/ Serial pc(USBTX, USBRX); ///*Creat I2C master*/ I2C i2c_master(p9, p10); void serial_init(){ pc.format(8, SerialBase::None, 1); pc.baud(38400); } void i2c_init(){ i2c_master.frequency(350000); } void main_init(){ led1 = 1; led2 = 0; led3 = 0; led4 = 0; fpga_rstb = 0; i2c_init(); serial_init(); i2c_master.start(); pc.printf("Mbed is ready!"); } /* Main function */ int main() { char i2cWriteTest[4] = {0x13, 0x8a, 0xac, 0x35}; char i2cReadTest[4] = {0x13, 0x8a, 0x00, 0x00}; int ack; main_init(); while (1) { char c = pc.getc(); if(c=='s'){ fpga_rstb = 0; //reset FPGA wait_ms(10); fpga_rstb = 1; //enable FPGA wait_ms(10); //i2c_keyEntry(i2c_master); ack+=i2c_word_write(i2c_master,i2cWriteTest); wait_ms(10); ack+=i2c_word_read(i2c_master,i2cReadTest); led1 = ack; pc.printf("d[0]=%2d\n",i2cReadTest[3]); pc.printf("d[1]=%2d\n",i2cReadTest[2]); } if(c=='t'){ fpga_rstb = 0; //disable FPGA led1 = 0; } } // fpga_rstb.write(1); // // wait_us(10000); //10ms // //// i2c_master.start(); //// wait_ms(200); //// i2c_master.stop(); // // ack+=i2c_keyEntry(i2c_master); // // //ack+=ctrPort_ReadActive(i2c_master); // buff[0] = 0x00; // buff[1] = 0x30; // buff[2] = 0x00; // buff[3] = 0x01; // // ack+=i2c_word_write(i2c_master, buff); // buff[0] = 0x00; // buff[1] = 0x0A; // buff[2] = 0x00; // buff[3] = 0x00; // // ack+=i2c_word_read(i2c_master, buff); // // wait_us(100); // // pc.printf("d[0]=%2d\n", buff[3]); // pc.printf("d[1]=%2d\n", buff[2]); // pc.printf("ack=%2d\n", ack); // pc.printf("endl\n"); // // // while (1) { // led1 = !led1; // wait(1); // } }