1 Reply Latest reply on Oct 1, 2019 12:05 AM by YatheeshK_36

    CY7C65215-32LTXI Device Open Failed if There are several Devices with FX3 Chipset

    AdPe_4111016

      Hi,

       

      I am developing a Test board which using the CY7C65215-32LTXI for USB-I2C interface. I wrote a the I2C driver based on the Example from the USB-Serial-SDK. It works fine up until I connected 2 Cypress FX3 Devices. If 2 Cypress FX3 Devices is present in the system, the CyOpen (From the USB Serial API) will fail in opening the Device. Other occurence, CyOpen can access the CY7C65215-32LTXI, but then if I will try to I2C write to the slave following Failure will occure: CY_ERROR_REQUEST_FAILED.

       

      Is there anything wrong I am doing in creating the I2C driver? The FX3 chipset is used by Passmark Loopback USB 3 Dongle. Below is my code for the i2c_driver:

       

      /*

      ## Cypress USB-Serial Windows Example source file (i2cmaster.cpp)

      ## ===========================

      ##

      ##  Copyright Cypress Semiconductor Corporation, 2013-2014,

      ##  All Rights Reserved

      ##  UNPUBLISHED, LICENSED SOFTWARE.

      ##

      ##  CONFIDENTIAL AND PROPRIETARY INFORMATION

      ##  WHICH IS THE PROPERTY OF CYPRESS.

      ##

      ##  Use of this file is governed

      ##  by the license agreement included in the file

      ##

      ##     <install>/license/license.txt

      ##

      ##  where <install> is the Cypress software

      ##  installation root directory path.

      ##

      ## ===========================

      */

       

       

       

       

      // i2cmaster.cpp : Defines the entry point for the console application.

      //

       

       

      #include "stdafx.h"

       

       

      #include <stdio.h>

      #include <windows.h>

      #include <dbt.h>

      #include <conio.h>

      #include "C:\Users\jordy.susanto\Documents\USB-Serial SDK\library\cyusbserial\CyUSBSerial.h"

       

       

      /** ****************

      Data Definitions

      *** **************** */    

       

       

      // Define VID & PID

      // These numbers depends on individual products

      #define VID 0x04B4

      #define PID 0x000A

       

       

      //Variable to store cyHandle of the selected device

      CY_HANDLE cyHandle2;

      //Varible to capture return values from USB Serial API

      CY_RETURN_STATUS cyReturnStatus;

       

       

      //CY_DEVICE_INFO provides additional details of each device such as product Name, serial number etc..

      CY_DEVICE_INFO cyDeviceInfo, cyDeviceInfoList[16];

       

       

      //Structure to store VID & PID defined in CyUSBSerial.h

      CY_VID_PID cyVidPid;

       

       

      //Variables used by application

      UINT8 cyNumDevices;

      unsigned char deviceID[16];

       

       

      /** ****************

      Functions

      *** **************** */    

       

       

       

       

      /*

      Function Name: CY_RETURN_STATUS I2CMaster(int deviceNumber)

      Purpose: Demonstates how to communicate with I2C EEPROM connected on USB Serial DVK

      - Demonstrates how to set/get configuration of I2C device

      - Demonstrates how to perform read/write operations

      Arguments:

      deviceNumber - The device number identified during the enumeration process

      Retrun Code: returns falure code of USB-Serial API

      */

       

       

      int _httoi(const TCHAR* value)

      {

      struct CHexMap

      {

      TCHAR chr;

      int value;

      };

      const int HexMapL = 16;

      CHexMap HexMap[HexMapL] =

      {

        {'0', 0}, {'1', 1},

        {'2', 2}, {'3', 3},

        {'4', 4}, {'5', 5},

        {'6', 6}, {'7', 7},

        {'8', 8}, {'9', 9},

        {'A', 10}, {'B', 11},

        {'C', 12}, {'D', 13},

        {'E', 14}, {'F', 15}

      };

      TCHAR* mstr = _tcsupr(_tcsdup(value));

      TCHAR* s = mstr;

      int result = 0;

      if (*s == '0' && *(s + 1) == 'X') s += 2;

      bool firsttime = true;

      while (*s != '\0')

      {

      bool found = false;

      for (int i = 0; i < HexMapL; i++)

      {

      if (*s == HexMap[i].chr)

      {

      if (!firsttime) result <<= 4;

      result |= HexMap[i].value;

      found = true;

      break;

      }

      }

      if (!found) break;

      s++;

      firsttime = false;

      }

      free(mstr);

      return result;

      }

       

       

      int I2CMaster(int deviceNumber, int address, int reg_address, int MSB, int LSB)

          {   

          CY_I2C_CONFIG cyI2CConfig;

          CY_DATA_BUFFER cyDatabuffer;       

          CY_I2C_DATA_CONFIG cyI2CDataConfig;

       

       

          CY_RETURN_STATUS rStatus;

       

       

          int interfaceNum = 0;

          unsigned char bufferWrite[3], bufferRead[2];

       

       

       

       

          // Configure the I2C

          cyI2CDataConfig.isStopBit = true;

          cyI2CDataConfig.slaveAddress = address;

       

       

          

       

       

          //Open the device at deviceNumber

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

      if (rStatus != CY_SUCCESS)

       

       

      {

       

       

      printf("I2C Device open failed... %d \n", rStatus);

      CyClose(cyHandle2);

      return rStatus;

       

       

      }

          // Get configuration

       

          // Set configuration

       

       

       

       

          // I2C Read/Write operations

       

       

          int success = 0, rsuccess = 0, rfailure = 0, failure = 0, length, index;   

       

       

          int i2cComplete = 0, intError = 0;

       

       

       

       

       

       

       

       

          // Page size of I2C on DVK is 64-bytes

          // Total length = length + 3 command bytes

       

          // Initialize the write buffer to 0xAA       

       

       

       

       

       

          //The first two bytes of the buffer are page address of I2C       

          bufferWrite[0]= reg_address; //MSB of the page address

          bufferWrite[1] = MSB;

      bufferWrite[2] = LSB;// LSB of page address, set to 0 as this applicate attempts to write at page boundery

       

       

          //Initialize the CY_DATA_BUFFER variable

          cyDatabuffer.buffer = bufferWrite;

       

       

          //Initialize the CY_I2C_DATA_CONFIG variable

          cyI2CDataConfig.isStopBit = true;

          cyDatabuffer.length = 3;

       

       

      rStatus = CyI2cReset(cyHandle2, 1);

      if (rStatus != CY_SUCCESS) {

      printf("%d", rStatus);

      CyClose(cyHandle2);

      return rStatus;

      }

          rStatus = CyI2cWrite (cyHandle2, &cyI2CDataConfig, &cyDatabuffer, 5000);

          if (rStatus != CY_SUCCESS){

      rStatus = CyI2cReset(cyHandle2, 1);

      if (rStatus != CY_SUCCESS) {

      printf("%d", rStatus);

      CyClose(cyHandle2);

      return rStatus;

      }

      printf("%d", rStatus);

      CyClose(cyHandle2);

              return rStatus;

              }

       

       

       

       

       

       

       

       

       

       

          // Peform I2C Read operation

          // Initialize read buffer to zeros

       

       

          //Initialize the CY_DATA_BUFFER variable to point to Read Buffer

          //We are interested to read all the data written.

          cyDatabuffer.buffer = bufferRead;

      cyDatabuffer.length = 2;

       

       

          //Initialize the CY_I2C_DATA_CONFIG variable

          cyI2CDataConfig.isStopBit = true;

          cyI2CDataConfig.isNakBit = true;

       

       

          intError = 0;

       

       

          rStatus = CyI2cRead (cyHandle2, &cyI2CDataConfig, &cyDatabuffer, 5000);

      if (rStatus != CY_SUCCESS) {

      rStatus = CyI2cReset(cyHandle2, 1);

      if (rStatus != CY_SUCCESS) {

      printf("%d", rStatus);

      CyClose(cyHandle2);

      return rStatus;

      }

      printf("%d", rStatus);

      CyClose(cyHandle2);

      return rStatus;

      }

       

       

          //Data verification phase

       

       

      printf("%d\n", bufferRead[0]);

      printf("%d", bufferRead[1]);

       

       

       

       

          // Close the handle to I2C device

          return CyClose(cyHandle2);

          }

       

       

       

       

      /*

      Function Name: int FindDeviceAtSCB0()

      Purpose: Demonstates how to enumerate and find device from the list of devices.

      - Demonstrates how to use deviceBlock member in DEVICE_INFO structure            

      Arguments: None

       

       

      Retrun Code: returns -1, if no device is present or deviceIndex of the device.

      */

       

       

      int FindDeviceAtSCB0()

      {

      CY_VID_PID cyVidPid;

       

       

      cyVidPid.vid = VID; //Defined as macro

      cyVidPid.pid = PID; //Defined as macro

       

       

      //Array size of cyDeviceInfoList is 16

      cyReturnStatus = CyGetDeviceInfoVidPid(cyVidPid, deviceID, (PCY_DEVICE_INFO)& cyDeviceInfoList, &cyNumDevices, 16);

       

       

      int deviceIndexAtSCB0 = -1;

      for (int index = 0; index < cyNumDevices; index++) {

      // Find the device at device index at SCB0

      if (cyDeviceInfoList[index].deviceBlock == SerialBlock_SCB1 && cyDeviceInfoList[index].deviceType[0] == 3)

      {

      deviceIndexAtSCB0 = index;

      }

      }

      return deviceIndexAtSCB0;

      }

       

       

      /** ********************************

      Application main() function

      *** ******************************** */    

       

       

      int _tmain(int argc, _TCHAR* argv[])

          {

      int address, reg_address, MSB, LSB;

       

       

      address = _httoi(argv[1]);

      reg_address = _httoi(argv[2]);

      MSB = _httoi(argv[3]);

      LSB = _httoi(argv[4]);

       

       

          //Assmumptions:

          //1. SCB0 is configured as I2C

       

       

          int deviceIndexAtSCB0 = FindDeviceAtSCB0();

       

       

       

       

          //Open the device at deviceIndexAtSCB0

          if (deviceIndexAtSCB0 >= 0)

              {       

       

       

              //Assuming that device at index is I2C device

              //Device Open, Close, Configuration, Data operations are handled in the function I2CMaster

       

       

              int status = I2CMaster(deviceIndexAtSCB0, address, reg_address, MSB, LSB);

       

       

              if (status == CY_SUCCESS)

                  {

      CyClose(cyHandle2);

                  }

              else

                  {

      CyClose(cyHandle2);

                  }

       

       

              } //cyNumDevices > 0 && cyReturnStatus == CY_SUCCESS

       

       

          return 0;

          }

       

      Could be a interference between the USB Serial Driver API and the FX3 API?

      Thank you for the support