4 Replies Latest reply on Oct 3, 2018 5:48 AM by SrinathS_16

    USB Serial API: CyI2cWrite returns SUCCESS on device NAK?

    KyTr_1955226

      Hi,

       

      I'm running into an issue with the cyusbserial USB Serial API. Specifically the CyI2cWrite function using an CY7C65211 USB to Serial bridge on the CYUSB234 DVK.  I need to be able to see if a device is present at a certain address at the start of my application.  I'm sending an address + 1 data byte in order to determine if a device is present at that address (although I doubt the data byte is necessary).  If the Address gets NAKed, the device is not there.  According to documentation, CyI2cWrite should return a status of CY_ERROR_I2C_NAK_ERROR in this case, but what I'm seeing is that regardless of the NAK, CyI2cWrite is returning CY_SUCCESS.

       

      The transmission looks as follows:

      Nothing too exciting going on with the transmission itself, no device is present at that address, but my CyI2cWrite call is returning CY_SUCCESS on this transmission.  It also doesn't seem to be waiting long enough for the timeout, which I have set to 5 seconds in this CyI2cWrite call.  If I'm not mistaken, shouldn't it wait on that NAK for the timeout period then return CY_ERROR_I2C_NAK_ERROR?

       

      Any thoughts/suggestions would are appreciated.

      Thanks,

      - Kyle

        • 1. Re: USB Serial API: CyI2cWrite returns SUCCESS on device NAK?
          SrinathS_16

          Hello Kyle,

           

          Please check using the example applications that come with the USB-Serial SDK. I have modified the address parameter of the CY_I2C_DATA_CONFIG structure (such that it does not match with the address of the on-board EEPROM) and found the CY_ERROR_I2C_NAK_ERROR on the CyI2cWrite() function.  Attached is the screenshot of the error.

           

          Best regards,

          Srinath S

          • 2. Re: USB Serial API: CyI2cWrite returns SUCCESS on device NAK?
            KyTr_1955226

            You're right, it works properly returning an error code with the example i2cmaster application, but that doesn't really help determine why it doesn't work here:

            private unsafe CY_RETURN_STATUS Enter_Bootloader(uint addr)
                    {
                        CY_RETURN_STATUS cy_stat;
                        byte[] transfer = new byte[63];
            
                        fixed (IntPtr* hdl = &handle)
                        {
                            cy_stat = CyOpen(I2C_Devicenum, I2C_Interfacenum, hdl);
                        }
                        WriteLog(Color.Black, 0, "Open: " + cy_stat.ToString());
            
                        fixed (CY_I2C_CONFIG* cfg = &cyI2CConfig)
                        {
                            cy_stat = CyGetI2cConfig(handle, cfg);
            
                            cyI2CConfig.Frequency = 100000;
                            cyI2CConfig.isMaster = 1;
            
                            cyI2CDataConfig.slaveAddress = ((uint)addr) >> 1;
                            cyI2CDataConfig.isStopBit = 0x00;
                            cyI2CDataConfig.isNakBit = 0x00;
            
                            cy_stat = CySetI2cConfig(handle, cfg);
                        }
                        WriteLog(Color.Black, 0, "Config: " + cy_stat.ToString());
            
                        transfer[0] = 0xEF;
                        cyDatabuffer.length = 1;
                        fixed (byte* b = transfer)
                        {
                            cyDatabuffer.buffer = b;
                            fixed (CY_I2C_DATA_CONFIG* d = &cyI2CDataConfig)
                            {
                                fixed (CY_DATA_BUFFER* buf = &cyDatabuffer)
                                {
                                    cy_stat = CyI2cWrite(handle, d, buf, 5000);
                                }
                            }
                        }
            
                        WriteLog(Color.Black, 0, "Write: " + cy_stat.ToString());
                        return cy_stat;
                    }
            

             

            You can see I have a logging window set up to return the status of each step.

             

            When the transmission looks like:

            • 3. Re: USB Serial API: CyI2cWrite returns SUCCESS on device NAK?
              KyTr_1955226

              Found something almost immediately after posting my last message.

               

              Turns out cyDataBuffer.length must be greater than 1 in order to throw the error?  Once I changed cyDataBuffer.length = 2 it started to return CY_ERROR_I2C_NAK_ERROR.

               

              Does this mean the length parameter is the length of the transmission including the address?  I thought it was for the number of data bytes after the address.  Even if that's the case, if I have the length parameter set to 1, why would it still return CY_SUCCESS if the address gets no response on the bus?  I would think that regardless of length, if the master sends out an address and does not get an ACK it would always see that as an error condition.

              • 4. Re: USB Serial API: CyI2cWrite returns SUCCESS on device NAK?
                SrinathS_16

                Hello Kyle,

                 

                We are able to reproduce the issue at our end and we have found that it was due to an incompatibility with the visual studio compiler. The cyusbserial.dll was built using the VS2008 and hence is not being compatible with later versions of Visual Studio.

                 

                We are processing internally to release the source of the cyusbserial.dll so that it can be compiled across different Visual Studio versions and will be released soon.

                 

                Best regards,

                Srinath S