CyUSBS236 I2C to external device

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DeCh_4514661
Level 1
Level 1
5 replies posted 5 questions asked First reply posted

Hi Cypress,

I have CyUSBS236 DVK board and wanted to connect external I2C device to it.

I configured SCB0 to I2C and set SCB0 "jump 17" and "jump 20" to "1 and 2", which means I can connect external device from header pin 5 (GPIO3) and 7 (GPIO4).

My external device address is 0x48, and both SDA and SCL are pulled up to VCC (3.3V).

I first search onboard I2C

rStatus = CyGetListofDevices(&numDevices);

     if ((rStatus != CY_SUCCESS) || (numDevices == 0))

        {

            printf(" Did not get it");

        }

     for (DeviceIdx = 0; DeviceIdx < numDevices; DeviceIdx++)

        {

            rStatus = CyGetDeviceInfo(DeviceIdx, &DeviceInfo);

            if (rStatus != CY_SUCCESS)

            {

               continue;

            }

            for (InterfaceIdx = 0; InterfaceIdx < DeviceInfo.numInterfaces; InterfaceIdx++)

            {

                 if (DeviceInfo.deviceType[InterfaceIdx] == CY_TYPE_I2C)

                 {

                          deviceNumber=DeviceIdx;

                          interfaceNum=InterfaceIdx;

                          printf("found I2C DeviceIndex: %d, InterfaceIndex: %d  \n", DeviceIdx, InterfaceIdx);

                                            

                 }

            }

        }

     

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

        if (rStatus != CY_SUCCESS)

        {

           printf("CY_I2C: Open failed \n");

        }

Up to here every thing is ok, but when I

     CY_I2C_CONFIG cyI2CConfig;

     CY_DATA_BUFFER cyDataBuffer;

     CY_I2C_DATA_CONFIG cyI2CDataConfig;

     unsigned char readBuffer[4096], writeBuffer[4096];

     UINT32 timeout = 5000;

     cyI2CDataConfig.slaveAddress = 0x48;

     cyI2CDataConfig.isNakBit = true;

     cyI2CDataConfig.isStopBit = true;

       

     memset(writeBuffer, 0x00, 4096);

     cyDataBuffer.buffer = writeBuffer;

     cyDataBuffer.buffer[0] = 0x01;    

     cyDataBuffer.buffer[1] = 0xc4;

     cyDataBuffer.buffer[2] = 0xd3;

    

     cyDataBuffer.length = 3;

     rStatus = CyI2cWrite(handle, &cyI2CDataConfig, &cyDataBuffer, timeout);

       

     if (rStatus != CY_SUCCESS)

        {

           printf("ADC setting fail \n");

        }

    I got error,

   Could anyone give me some advices?

 

   Thank you!

  Derlin

0 Likes
1 Solution

Hello,

Slave address to which the USB-Serial device is communicating with, is stored in the structure CY_I2C_DATA_CONFIG.

If the 7bit address of the slave is 0x48 the set cyI2CDataConfig.slaveAddress = 0x48 (CY_I2C_DATA_CONFIG cyI2CDataConfig).

Return status 17 is a NAK from the slave device. Please check if the slave address is proper.

Best Regards,

Yatheesh

View solution in original post

0 Likes
7 Replies