Testing I2C by dump content

Dependencies:   mbed FastPWM

Committer:
stefkpl
Date:
Fri Oct 14 10:10:52 2016 +0000
Revision:
1:3a2023b0563c
Parent:
0:392956e976ae
Test is OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefkpl 1:3a2023b0563c 1 /***************************************************************************
stefkpl 1:3a2023b0563c 2 DUMP I2C
stefkpl 1:3a2023b0563c 3 +----------+
stefkpl 1:3a2023b0563c 4 Do an I2C Dump for testing.
stefkpl 1:3a2023b0563c 5
stefkpl 1:3a2023b0563c 6 Fast PWM is use for dump ov7670 REG, I must have xclock for using I2C.
stefkpl 1:3a2023b0563c 7 You can remove them.
stefkpl 1:3a2023b0563c 8
stefkpl 1:3a2023b0563c 9 Stéphane PEREZ (stefkpl)
stefkpl 1:3a2023b0563c 10
stefkpl 1:3a2023b0563c 11 ****************************************************************************/
stefkpl 1:3a2023b0563c 12
stefkpl 0:392956e976ae 13 #include "mbed.h"
stefkpl 1:3a2023b0563c 14 #include "FastPWM.h"
stefkpl 1:3a2023b0563c 15
stefkpl 0:392956e976ae 16 // Test DUMP I2C
stefkpl 1:3a2023b0563c 17 #define _ADDR (0x42)
stefkpl 1:3a2023b0563c 18 #define CAMERA_CLK_PERIOD .1// ==> 10Mhz 100nS
stefkpl 1:3a2023b0563c 19 #define VSYNC D9
stefkpl 0:392956e976ae 20
stefkpl 0:392956e976ae 21 I2C i2c(I2C_SDA, I2C_SCL);
stefkpl 0:392956e976ae 22
stefkpl 0:392956e976ae 23 DigitalOut myled(LED1);
stefkpl 1:3a2023b0563c 24
stefkpl 1:3a2023b0563c 25 FastPWM __xclk(VSYNC);
stefkpl 1:3a2023b0563c 26
stefkpl 0:392956e976ae 27 Serial pc(SERIAL_TX, SERIAL_RX);
stefkpl 1:3a2023b0563c 28 char value;
stefkpl 1:3a2023b0563c 29 char cmd;
stefkpl 0:392956e976ae 30 int main()
stefkpl 0:392956e976ae 31 {
stefkpl 1:3a2023b0563c 32 __xclk.period_us(CAMERA_CLK_PERIOD);
stefkpl 1:3a2023b0563c 33 __xclk.write(0.5);
stefkpl 1:3a2023b0563c 34
stefkpl 0:392956e976ae 35 pc.printf("Begin Scan\r\n");
stefkpl 1:3a2023b0563c 36
stefkpl 1:3a2023b0563c 37 for (char n=0; n<0xFF; n++){
stefkpl 1:3a2023b0563c 38
stefkpl 1:3a2023b0563c 39 i2c.write(_ADDR, &n, 1);
stefkpl 1:3a2023b0563c 40 i2c.read(_ADDR, &value, 1);
stefkpl 1:3a2023b0563c 41 pc.printf("addresse 0x%x \t- reg:0x%x \t- value:%d \t- 0x%X\r\n",_ADDR, n, value, value);
stefkpl 1:3a2023b0563c 42
stefkpl 1:3a2023b0563c 43 }
stefkpl 1:3a2023b0563c 44 // because n cannot be upper than 0xFF on the loop, and I don't want use another ... ;-)
stefkpl 1:3a2023b0563c 45 value = 0xFF;
stefkpl 1:3a2023b0563c 46 i2c.write(_ADDR, &value, 1);
stefkpl 1:3a2023b0563c 47 i2c.read(_ADDR, &value, 1);
stefkpl 1:3a2023b0563c 48 pc.printf("addresse 0x%x \t- reg:0x%x \t- value:%d \t- 0x%X\r\n",_ADDR, 0xFF, value, value);
stefkpl 1:3a2023b0563c 49
stefkpl 1:3a2023b0563c 50 pc.printf("End Scan\r\n");
stefkpl 0:392956e976ae 51
stefkpl 0:392956e976ae 52 while (1) {
stefkpl 0:392956e976ae 53 myled = !myled;
stefkpl 0:392956e976ae 54 wait(0.2);
stefkpl 1:3a2023b0563c 55 }
stefkpl 0:392956e976ae 56
stefkpl 0:392956e976ae 57 }
stefkpl 0:392956e976ae 58