You are here

sccb_read_reg example? | Cypress Semiconductor

sccb_read_reg example?

Summary: 2 Replies, Latest post by dv2 on 19 Sep 2016 12:43 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
dv2
user_55294358's picture
User
188 posts

 

Hi.

I ran across as below code to control i2c with Omnivision sensor(The device slave addresses are 0x78 for write and 0x79 for read.).

/* Functions for OmniVision Chips */
void sccb_read_reg(uint8_t reg, uint8_t *data)
{
    CyU3PReturnStatus_t apiRetStatus;
    CyU3PI2cPreamble_t preamble;
    preamble.buffer[0] = 0x60;
    preamble.buffer[1] = reg;
    preamble.buffer[2] = 0x61;
    preamble.length = 3;
    preamble.ctrlMask = 1 << 1;
    apiRetStatus = CyU3PI2cReceiveBytes(&preamble, data, 1, 0);
    if(apiRetStatus != CY_U3P_SUCCESS){
        CyU3PDebugPrint(8, "i2c Receive Failed, Error Code = %d\n\r", apiRetStatus);
    }else{
        CyU3PDebugPrint(8, "i2c Receive Data = %x,%x\n\r", reg, *data);
    }
}

void sccb_write_reg(uint8_t reg, uint8_t *data)
{
    CyU3PReturnStatus_t apiRetStatus;
    CyU3PI2cPreamble_t preamble;
    preamble.buffer[0] = 0x60;
    preamble.buffer[1] = reg;
    preamble.length = 2;
    preamble.ctrlMask = 0 << 2;
    apiRetStatus = CyU3PI2cTransmitBytes(&preamble, data, 1, 0);
    if(apiRetStatus != CY_U3P_SUCCESS){

        CyU3PDebugPrint(8, "i2c Send Failed, Error Code = %d\n\r", apiRetStatus);
    }else{
        CyU3PDebugPrint(8, "i2c Send Data = %x,%x\n\r", reg, *data);
    }
}

 

Also i found this code envolved in cyu3i2c.c. But I can't found how to implement and use this function.

Because It doesn't work when I used that, There is any response from SCL,SDA lines. can you let me know how to use this function with example?

below is my snippet code.

 

 

void sccb_read_reg(uint8_t reg, uint8_t *data)
{
    CyU3PReturnStatus_t apiRetStatus;
    CyU3PI2cPreamble_t preamble;
    preamble.buffer[0] = 0x42;
    preamble.buffer[1] = reg;
    preamble.buffer[2] = 0x43;
    preamble.length = 3;
    preamble.ctrlMask = 1 << 1;
    apiRetStatus = CyU3PI2cReceiveBytes(&preamble, data, 1, 0);
    if(apiRetStatus != CY_U3P_SUCCESS){
        CyU3PDebugPrint(8, "i2c Receive Failed, Error Code = %d\n\r", apiRetStatus);
    }else{
        CyU3PDebugPrint(8, "i2c Receive Data = %x,%x\n\r", reg, *data);
    }
}

void sccb_write_reg(uint8_t reg, uint8_t *data)
{
    CyU3PReturnStatus_t apiRetStatus;
    CyU3PI2cPreamble_t preamble;
    preamble.buffer[0] = 0x42;
    preamble.buffer[1] = reg;
    preamble.length = 2;
    preamble.ctrlMask = 0 << 2;
    apiRetStatus = CyU3PI2cTransmitBytes(&preamble, data, 1, 0);
    if(apiRetStatus != CY_U3P_SUCCESS){

        CyU3PDebugPrint(8, "i2c Send Failed, Error Code = %d\n\r", apiRetStatus);
    }else{
        CyU3PDebugPrint(8, "i2c Send Data = %x,%x\n\r", reg, *data);
    }
}

 

CyBool_t
CyFxSlFifoApplnUSBSetupCB (
        uint32_t setupdat0,
        uint32_t setupdat1
    )
{
    /* Fast enumeration is used. Only requests addressed to the interface, class,
     * vendor and unknown control requests are received by this function.
     * This application does not support any class or vendor requests. */

    uint8_t  bRequest, bReqType;
    uint8_t  bType, bTarget;
    uint16_t wValue, wIndex, wLength;////
    CyBool_t isHandled = CyFalse;

    ///////
    //uint16_t temp;
    //CyU3PReturnStatus_t status;
        /////

    /* Decode the fields from the setup request. */
    bReqType = (setupdat0 & CY_U3P_USB_REQUEST_TYPE_MASK);
    bType    = (bReqType & CY_U3P_USB_TYPE_MASK);
    bTarget  = (bReqType & CY_U3P_USB_TARGET_MASK);
    bRequest = ((setupdat0 & CY_U3P_USB_REQUEST_MASK) >> CY_U3P_USB_REQUEST_POS);
    wValue   = ((setupdat0 & CY_U3P_USB_VALUE_MASK)   >> CY_U3P_USB_VALUE_POS);
    wIndex   = ((setupdat1 & CY_U3P_USB_INDEX_MASK)   >> CY_U3P_USB_INDEX_POS);
    /////////////
    uint8_t  i2cAddr;
    /////////////
    wLength  = ((setupdat1 & CY_U3P_USB_LENGTH_MASK)  >> CY_U3P_USB_LENGTH_POS);

    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
/////////////////////
    if (bType == CY_U3P_USB_VENDOR_RQT)
    {
        /* Vendor command is sent by test applications. Start the loop that tries to keep the link
         * in U0.
         */
        gDoLpmDisable = CyTrue;

        switch (bRequest)
        {

........

........

///////////////////////////////////////
            case CY_FX_RQT_I2C_EEPROM_WRITE: //0xBA
            i2cAddr = 0x21 | ((wValue & 0x0007) << 1);
            status  = CyU3PUsbGetEP0Data(wLength, glEp0Buffer, NULL);
            if (status == CY_U3P_SUCCESS)
                {
                CyFxUsbI2cTransfer (wIndex, i2cAddr, wLength,
                glEp0Buffer, CyFalse);
                }
                break;

            case CY_FX_RQT_I2C_EEPROM_READ: //0xBB

                sccb_read_reg((uint8_t)wValue,  glEp0Buffer);

I'm not sure what am I wrong. I just received error message "i2c Receive Failed, Error Code = 68 ". what am I supposed to do for solving this problem?

And I have another question. basically Omnivision address register size consisted with 1 word size not 1 byte such as 0x3000..0x4301...,.. So i'd like to control with word size. what am I supposed to make a handle this?

Thanks for in advanced.

 

 

 

 

 

mady's picture
Cypress Employee
1022 posts

Hi,

I am also concerned about the register address size of OVT sensors. As you said, they are of one word, not one byte.

In order to use a sensor with 2 Byte Register address, please refer the reads/ writes in our example firmware: "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxusbi2cregmode"

Regards,

- Madhu Sudhan

 

dv2
user_55294358's picture
User
188 posts

I have some problem as below,
http://electronics.stackexchange.com/questions/258486/omnivision-ov7670-...

Can you help me please?

Log in to post new comments.