This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PC communication with 4710

Hello,

I found some I2C examples from Cypress.

But, I don't understand how to use it.

 

Here are some codes from example.

//Open the device at deviceNumber    

rStatus = CyOpen (deviceNumber, interfaceNum, &cyHandle);

if (rStatus != CY_SUCCESS)

{        

printf ("I2C Device open failed...\n");

return rStatus;

}

 

I believe that the I2C is successfully opened because this function returns CY_SUCCESS as 'rStatus',

Then I used 'CyI2cWrite (cyHandle, &cyI2CDataConfig, &cyDatabuffer, 5000)'

in order to change the mode of projector from 'Splash' to 'Test Patterns',

but this function returns 'CY_ERROR_I2C_DEVICE_BUSY'.

 

Can I have some codes to solve this problem?

 

Thanks,

  • Hello User,

    To be able communicate via I2C the cypress have to get the I2C bus first. I would like to refer you to another post in this forum (please see link below).

     https://e2e.ti.com/support/dlp__mems_micro-electro-mechanical_systems/f/1006/t/441756

    Are you following this steps ?

    Best regards,


    Nadine

  • I saw the post before, but I don't know how to set GPIO 5 and 9, wait for 6 to go high (prepare for I2C).
    Can I have the exact code for this step?
    Thanks.
  • Hello User,

    Have you downloaded the Cypress USB-Serial SDK ? It includes code examples and necessary documentation to program the Cypress. It can be downloaded under follow link: 

    http://www.cypress.com/documentation/software-and-drivers/usb-serial-software-development-kit

    It also includes the command to set and get GPIO values which is CyGetGpioValue and CySetGpioValue.

    I am more than happy to look over your code in case you run into any issues.

    Best regards,

    Nadine

     

     

  • Hello Nadine,

    I can successfully do 'GPIO5 High wait for GPIO6 to get High and then set GPIO9 high'.
    Then I would like to select 'Test Pattern Generator' as 'Input Source'.
    So I slightly modified the example code from Cypress as follows.

    -----------------------------------------------------------------------------------------------------------
    bufferWrite[0]= 0x05; // Write Input Source Select
    bufferWrite[1] = 0x01; // Test Pattern Generator

    //Initialize the CY_DATA_BUFFER variable
    cyDatabuffer.buffer = bufferWrite;

    //Initialize the CY_I2C_DATA_CONFIG variable
    cyI2CDataConfig.slaveAddress = 0x1B; // Is this OK? The slave address can not be assigned by odd number according to the manual
    cyI2CDataConfig.isStopBit = true;
    cyI2CDataConfig.isNakBit = true;
    cyDatabuffer.length = 2;

    rStatus = CyI2cWrite (cyHandle, &cyI2CDataConfig, &cyDatabuffer, 5000);
    if (rStatus != CY_SUCCESS)
    {
    printf ("CyI2cWrite Failed ...retrying %d \n", rStatus);
    return rStatus;
    }
    -----------------------------------------------------------------------------------------------------------

    But I got a CY_ERROR_I2C_DEVICE_BUSY response.

    Thanks for any help.

    Best regards,
    DRPark

  • Hello User,

    It still looks like that you don't have access to the I2C bus.The address 0x1B is correct.

    You have to set GPIO5 High wait for the MSP430 to give you access to the I2C bus which is indicated by GPIO6 going High. GPIO5 has to stay High as long as you are communicating over the bus. After GPIO6 goes High you can set GPIO9 High.

    After your finished the communication over I2C you can set GPIO5 to Low again.

    Best regards,

    Nadine

  • Thanks for relpy.

    I am using following codes for initialization, GPIO settings and I2C writing.
    -----------------------------------------------------------------------------------------------------------------------------
    CY_I2C_CONFIG cyI2CConfig;
    CY_DATA_BUFFER cyDatabuffer;
    CY_I2C_DATA_CONFIG cyI2CDataConfig;

    CY_RETURN_STATUS rStatus;

    int interfaceNum = 0;
    unsigned char bufferWrite[4096], bufferRead[4096];
    int loopCount = 1000;
    unsigned char bytesPending = 0;

    //Open the device at deviceNumber
    rStatus = CyOpen (deviceNumber, interfaceNum, &cyHandle); // deviceNumber is 0

    // GPIO setting codes(begin)
    ..............................................
    // GPIO setting codes(end)

    // Set configuration
    // Configure I2C with different settings
    cyI2CConfig.frequency = 100000;
    //cyI2CConfig.slaveAddress = 0x1B; // This makes the return value of CySetI2cConfig as CY_ERROR_INVALID_PARAMETER

    cyI2CConfig.isMaster = 1; // This makes the retur value of CyI2cWrite as CY_SUCCESS, but ...
    //cyI2CConfig.isMaster = 0; // This makes the retur value of CyI2cWrite as CY_ERROR_I2C_DEVICE_BUSY

    rStatus = CySetI2cConfig (cyHandle, &cyI2CConfig);
    if (rStatus != CY_SUCCESS)
    {
    printf ("CySetI2cConfig returned failure code.\n");
    return rStatus;
    }
    printf("Setting new I2C configuration successful.\n");
    -----------------------------------------------------------------------------------------------------------------------------------

    If I set the device as master by CySetI2cConfig, the CyI2cWrite function returns CY_SUCCESS.
    But there is no variation of projector.

    If I open the device as slaveby CySetI2cConfig, the CyI2cWrite function returns CY_ERROR_I2C_DEVICE_BUSY .

    I think that Cypress USB should be opened as slave.
    Am I right?

    Best regards,
    DRPark
  • Hello DRPark, 


    On our EVM's the Cypress is acting as a Master and has to be setup this way. You don't need the slaveAddress in your Set configuration. The slaveAddress will be defined in your data configuration as your code snapshot showed before. Your data configuration part is correct.

    The slave address of 0x1B is correct. Can you please point me to the document which mentions that the slave address cannot be an odd number?

    If you are still getting a lot of CY_ERROR_I2C_Device_BUSY returns you might want to try adding a retry loop. We currently have a retry loop with a count of 5 in our code. You can adjust the count number accordingly if needed.

    Please let me know if you have any further questions.


    Best regards,


    Nadine