1

我是嵌入式的新手,甚至是相机传感器的新手——请多多包涵。我正在尝试连接 OV2640 相机模块(OV2640 数据表带分线板的模块)。所以我连接了以下内容:

  • OV2640 - LPC1768
  • 地线------- p1(地线)
  • VCC ------- p40 (Vout - 3.3V)
  • SDA -------- p28 (I2C SDA)
  • SCL -------- p27 (I2C SCL)

我试图让它通过SCCB工作,这就是连接 I2C 的原因。但似乎我无法正确设置。

这是我现在拥有的代码:

#include <stdio.h>
#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx to the PC

I2C cam(p28, p27);      // I2C

int main() {
    pc.printf("Starting new program\r\n");
    cam.start();

    int          addressCOM7  = 0x12;
    int          addressCLKRC = 0x11;
    int          addressCOM2  = 0x09;
    const char   data         = 1;
    int          length       = 8; 
    bool         repeated     = false;
    int          rtn          = -1;

    cam.frequency(400000); 
    pc.printf("Camera I2c set to 400,000Hz \r\n");

    rtn = cam.write(addressCOM7, "1", addressCOM7 + data);
    if ( rtn == 0)pc.printf("COM7 set to 1. \r\n");
    else          pc.printf("Error Setting COM7 to 1. \r\n");
    rtn = cam.write(addressCLKRC, &data, addressCLKRC + data);
    if (rtn == 0) pc.printf("CLKRC set to 1. \r\n");
    else          pc.printf("Error Setting CLKRC to 1. \r\n");
    rtn = cam.write(addressCOM2, &data, addressCOM2 + data);
    if (rtn == 0) pc.printf("COM2 set to 1. \r\n");
    else          pc.printf("Error Setting COM2 to 1. \r\n");

    int address = 0x30;
    char readData[128];

    strcpy (readData,"");

    while(1) {
        cam.read(address, readData, 128);
        wait(2.0);
        pc.printf("1 =  '%s'\r\n", readData);       
    }
}

我无法通过 I2C 写入或读取 - 我在这里做错了什么?

另外,相信 XCLK 需要绑定到 OV2640 模块,如何从 LPC1768 微控制器完成?

4

0 回答 0