CyUSBSerial: CyI2cWrite/Read failing on Windows

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

cross mob
karac_3142546
Level 2
Level 2
First like given

Hi,

I have a custom device built with a CY7C65211 chip, configured into I2C master mode. This device is controlled by my custom host software using the CyUSBSerial library.

Everything works just fine on Linux and Mac, but compiling the exact same host software on MSVC, I'm not getting a response from the CY7C65211.

The exact problem is in CyI2cWrite() and CyI2CRead() functions. The first time Write() is called, it returns CY_SUCCESS. All subsequent calls return CY_ERROR_REQUEST_FAILED (numeric 6). This error is documented as being returned "if the device type is not I2C", which sounds rather weird in the case. Watching on the I2C pins on a oscilloscope, no data is sent on the line, even when CyI2cWrite() has returned CY_SUCCESS.

These errors occur when I am using the Cypress-provided CyUSBSerial.dll, so I cannot step into the driver to figure out what exactly goes wrong. Despairing, I ported the Linux/Mac libcyusbserial to Windows with libusb/winusb, and with that I am seeing a timeout with the CyI2cWrite() (and nothing on the I2C pins, again). I do not know if this problem is related - but I am seeing the exact same symptoms as with the closed source driver...

Another peculiarity is that with the Cypress-provided .dll, CyLibraryInit() and CyLibraryExit() functions were not available (I was seeing linker errors). Is this intentional or another symptom of the problems I am facing? The API documentation did not mention that these two functions

would be missing from the CyUSBSerial.dll.

Any suggestions would be greatly appreciated. Or failing that, an explanation on what exactly has happened, when CyUSBSerial returns _REQUEST_FAILED error.

thank you in advance,

kalle

0 Likes
1 Solution

Figured it out: the culprit was the definition of the BOOL type.

The windows library not being open source was compiled with BOOL from windows.h.

For the Linux & Mac stuff, I had included stdbool.h, which then was included in the windows build too.

This meant the BOOL in the library was different from the BOOL in the application. Including windows.h makes my application work.

So, an SDK bug - CyUSBSerial.h should include the correct header, platform dependently.

View solution in original post

0 Likes
4 Replies
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello Kalle,

- Please use the default example applications that come with the USB-Serial SDK and check the Read/Write functions.

- Kindly, let me know if you are using console application in C++ and how you are referencing the DLL file in the project. Also, let me know if you face linker errors even without CyLibraryInit() and CyLibraryExit() functions. Both the CyUSBSerial.LIB and CyUSBSerial.DLL files contain the same functions.

Best regards,

Srinath S

0 Likes

Hi Srinath, thanks for your reply.

I forgot about the examples in the SDK - silly me. Yes, the i2cmaster project does seem to work to the extent that I see I2C signaling on the oscilloscope (with our device). I now have checked & copied meticulously all the calls to Cy*() functions from the i2cmaster project to mine, but I cannot still see anything on the I2C.

I could of course be just missing some trivial detail, but I have read through the code several times now... Should be identical. I'll re-check a few times more

The main difference now is - my project is a C project, not C++, and the Visual Studio project files are generated with CMake. And I am linking the CyUSBSerial library to a library (DLL) of my own, which then is

linked to several applications - the one I am testing with is a command-line C application.

The relevant parts of the CMakeLists.txt are:

link_directories("C:/Program Files/Cypress/USB-Serial SDK/library/cyusbserial/x86")

include_directories("C:/Program Files/Cypress/USB-Serial SDK/library/cyusbserial")

set(CYPRESS_LIB cyusbserial)

add_library(my_library SHARED ${SRC}

target_link_libraries(my_library ${CYPRESS_LIB})

After removing CyLibraryInit() and CyLibraryExit(), there are no linker errors or warnings.

Any ideas? Thanks!

kalle

0 Likes

The C & CMake are red herrings.
I managed to compile the i2cmaster example with CMake, and it works fine. Also tried converting it from C++ to C, and I can still see I2C traffic. Finally I even split the i2cmaster.c into two source files, compiling a DLL and C command line application out of them - still works.

I guess I am just doing something stupid in my code

0 Likes

Figured it out: the culprit was the definition of the BOOL type.

The windows library not being open source was compiled with BOOL from windows.h.

For the Linux & Mac stuff, I had included stdbool.h, which then was included in the windows build too.

This meant the BOOL in the library was different from the BOOL in the application. Including windows.h makes my application work.

So, an SDK bug - CyUSBSerial.h should include the correct header, platform dependently.

0 Likes