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.
Diff: main.cpp
- Revision:
- 4:dd534b0b54dd
- Parent:
- 3:c4bdaf91371c
- Child:
- 5:92add1a06191
--- a/main.cpp Thu Jul 24 11:30:32 2014 +0000 +++ b/main.cpp Fri Jul 25 11:34:28 2014 +0000 @@ -1,99 +1,96 @@ #include "mbed.h" #include "MLX90393.h" -#include <string> +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); +SPI spi(p5, p6, p7); +I2C i2c(p28, p27); + +MLX90393 mlx_spi(p8,&spi); +MLX90393 mlx_i2c(0x19,&i2c); + +char read_buffer_main[10]; int main() { - //insert i2c variables - int spi_mode_90393; - int spi_bits_90393; - - //char u8_spi_read_buffer[8]; - //char u8_spi_write_buffer[7]; - char pcCommand; - //char hostAddress; - char dataByte1; - char dataByte2; - char address; - int tempData1; - int tempData2; - int tempData3; - DigitalOut slaveSelect(p26); - DigitalOut myled1(LED1); - DigitalOut myled2(LED2); - DigitalOut myled3(LED3); - DigitalOut myled4(LED4); - - Serial pc(USBTX, USBRX); // tx, rx - pc.baud(9600); - printf("**********Init Serial communication complete********* \n\r"); - - //SPI information is requested from the MLX90393 class. - spi_mode_90393 = MLX90393::spi_mode; - spi_bits_90393 = MLX90393::spi_bits; - printf("**********Get class variables complete********** \n\r"); - - //Creation of an SPI object - SPI spi(p5, p6, p7); - spi.format(spi_bits_90393,spi_mode_90393); - spi.frequency(2000); - printf("**********SPI complete********** \n\r"); - - //Creation sensor object + calling constructor object - /* - myled1=!myled1; - myled2=tempData1; - myled3=tempData2; - myled4=tempData3; - */ - - MLX90393 sensor(p26,&spi); - printf("**********Creat sensor object complete********** \n\r"); - pcCommand = 4; - while (1) { - pc.scanf(" %i, %i, %i, %i", &pcCommand, &tempData1, &tempData2, &tempData3); - - switch (pcCommand) { + pi.format(8,3); + //OR + //spi.format(MLX90393::spi_bits,MLX90393::spi_mode); - case 0: { - sensor.copyEEpromToRam_spi(); - break; - } - case 1: { - sensor.readEEpromToHost_spi(); - break; - } - case 2: { - - //pc.scanf(" %i, %i, %i", &dataByte2, &dataByte1, &address); - sensor.writeToEEprom_spi(tempData1,tempData2,tempData3); - break; - } - case 4: { + spi.frequency(1000000); + i2c.frequency(75000); + /* + __ ___ ______ _______. _______ ______ __ __ _______ .__ __. ______ _______ + | | |__ \ / | / || ____| / __ \ | | | | | ____|| \ | | / || ____| + | | ) | | ,----' | (----`| |__ | | | | | | | | | |__ | \| | | ,----'| |__ + | | / / | | \ \ | __| | | | | | | | | | __| | . ` | | | | __| + | | / /_ | `----. .----) | | |____ | `--' '--.| `--' | | |____ | |\ | | `----.| |____ + |__| |____| \______| |_______/ |_______| \_____\_____\\______/ |_______||__| \__| \______||_______| - sensor.getStatus_spi(); - break; - } - case 5: { - sensor.exitMode_spi(); - break; - } - case 6: { - sensor.startSingleMeasurementMode_spi(tempData1); - break; - } - case 7: { - sensor.readMeasurement_spi(tempData1); - break; - } - case 8: { - sensor.startBurstMode_spi(tempData1); - break; - } + */ + while (0) { + mlx_i2c.WR(read_buffer_main,0,0x7C,0); + pc.printf("[WR] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_i2c.RR(read_buffer_main,0,0); + pc.printf("[RR] - Status: %i MSB: %i LSB: %i\n",read_buffer_main[0],read_buffer_main[1],read_buffer_main[2]); + wait(1); + mlx_i2c.SB(read_buffer_main,0xF,0); + pc.printf("[SB] - Status: %i\n",read_buffer_main[0]); + wait(1); + for(int i=0 ; i<10; ++i) { + mlx_i2c.RM(read_buffer_main,0xF,0); + pc.printf("[RM] - Status: %i T= %i X= %i Y= %i Z= %i\n",read_buffer_main[0],256*read_buffer_main[1]+read_buffer_main[2],256*read_buffer_main[3]+read_buffer_main[4],256*read_buffer_main[5]+read_buffer_main[6],256*read_buffer_main[7]+read_buffer_main[8]); + wait(0.2); + } + wait(1); + mlx_i2c.EX(read_buffer_main,0); + pc.printf("[EX] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_i2c.SM(read_buffer_main,0xF,0); + pc.printf("[SM] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_i2c.RM(read_buffer_main,0xF,0); + pc.printf("[RM] - Status: %i T= %i X= %i Y= %i Z= %i\n",read_buffer_main[0],256*read_buffer_main[1]+read_buffer_main[2],256*read_buffer_main[3]+read_buffer_main[4],256*read_buffer_main[5]+read_buffer_main[6],256*read_buffer_main[7]+read_buffer_main[8]); + wait(1); + pc.printf("\n"); + } + /* + _______..______ __ _______. _______ ______ __ __ _______ .__ __. ______ _______ + / || _ \ | | / || ____| / __ \ | | | | | ____|| \ | | / || ____| + | (----`| |_) | | | | (----`| |__ | | | | | | | | | |__ | \| | | ,----'| |__ + \ \ | ___/ | | \ \ | __| | | | | | | | | | __| | . ` | | | | __| + .----) | | | | | .----) | | |____ | `--' '--.| `--' | | |____ | |\ | | `----.| |____ + |_______/ | _| |__| |_______/ |_______| \_____\_____\\______/ |_______||__| \__| \______||_______| + */ + while (1) { + mlx_spi.WR(read_buffer_main,0,0x7C,1); + pc.printf("[WR] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_spi.RR(read_buffer_main,0,1); + pc.printf("[RR] - Status: %i MSB: %i LSB: %i\n",read_buffer_main[0],read_buffer_main[1],read_buffer_main[2]); + wait(1); + mlx_spi.SB(read_buffer_main,0xF,1); + pc.printf("[SB] - Status: %i\n",read_buffer_main[0]); + wait(1); + for(int i=0 ; i<10; ++i) { + mlx_spi.RM(read_buffer_main,0xF,1); + pc.printf("[RM] - Status: %i T= %i X= %i Y= %i Z= %i\n",read_buffer_main[0],256*read_buffer_main[1]+read_buffer_main[2],256*read_buffer_main[3]+read_buffer_main[4],256*read_buffer_main[5]+read_buffer_main[6],256*read_buffer_main[7]+read_buffer_main[8]); + wait(0.2); } + wait(1); + mlx_spi.EX(read_buffer_main,1); + pc.printf("[EX] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_spi.SM(read_buffer_main,0xF,1); + pc.printf("[SM] - Status: %i\n",read_buffer_main[0]); + wait(1); + mlx_spi.RM(read_buffer_main,0xF,1); + pc.printf("[RM] - Status: %i T= %i X= %i Y= %i Z= %i\n",read_buffer_main[0],256*read_buffer_main[1]+read_buffer_main[2],256*read_buffer_main[3]+read_buffer_main[4],256*read_buffer_main[5]+read_buffer_main[6],256*read_buffer_main[7]+read_buffer_main[8]); + wait(1); + pc.printf("\n"); } } \ No newline at end of file