CY7C65215-32LTXI always times out when reading and writing SPI data under Ubuntu

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

cross mob
Jungle
Level 1
Level 1
First reply posted First question asked Welcome!

hi support team,

We call the chip, operate scb0 (I2C) and scb1 (SPI) normally on windows, and then transplant it to Ubuntu. I2C protocol works normally, SPI protocol reads and writes data, and the return status is timeout. It is normal to initialize cypress, open SPI, set SPI parameters and set IO status

-------------------------------------------------------------------

CY_DATA_BUFFER WriteBuffer;

UINT32 num = 1;
UCHAR buf[] = { 0x06 };

WriteBuffer.buffer = buf;
WriteBuffer.length = num;
WriteBuffer.transferCount = 0;

Status = CySpiReadWrite(s_SpiHandle,NULL,&WriteBuffer,TIMEOUT_MILLISECONDS);

//Status = CY_ERROR_IO_TIMEOUT

--------------------------------------

 

Thank you for your support

Best regards,

Jungle.

0 Likes
5 Replies
Meghavi
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 10 likes received

Hi,

- Can you please share the part of application that contains the CySpiReadWrite API so that we could review it?

- Also, can you please let us know if you had tried the example from the USB serial SDK on your board?

Regards

0 Likes
Jungle
Level 1
Level 1
First reply posted First question asked Welcome!

Hi,

The code works normally under windows.

Libcyusbserial.so library is installed under Ubuntu, in which I2C can also work normally, but the SPI protocol will report timeout when reading and writing. SPI codes are as follows:

 

#include "CyUSBSerial.h"
#include "stdio.h"

#define SPI_CLOCK_FREQUENCY_HZ     3000000
#define Gpio7    7
#define Gpio8    8
#define Gpio14   14
#define SPI_CLOCK_FREQUENCY_HZ     3000000
#define DLP_I2C_SLAVE_ADDRESS      (0X36 >> 1)
#define true 1 
#define false 0 
#define uint8_t unsigned char
#define NULL 0
#define TIMEOUT_MILLISECONDS   600  

CY_HANDLE s_SpiHandle;
BOOL CYPRESS_SPI_GetCyGpio(uint8_t GpioNum, uint8_t* Value)
{
    return CyGetGpioValue(s_SpiHandle, GpioNum, Value) == CY_SUCCESS;
}

BOOL CYPRESS_SPI_SetCyGpio(uint8_t GpioNum, uint8_t Value)
{
    return CySetGpioValue(s_SpiHandle, GpioNum, Value) == CY_SUCCESS;
}

int main() {
   
    CY_SPI_CONFIG SpiConfig = { 0 };
    CY_SPI_CONFIG SpiConfig2 = { 0 };
    CY_DEVICE_INFO deviceInfo = { 0 };
    CY_RETURN_STATUS  Status = 0;
#ifndef WIN32
    CyLibraryInit();
#endif // !WIN32

    int numDevs = 0;
    int devnum = 0;
    BOOL findSPI = false;

    CyGetListofDevices(&numDevs);
    for (devnum = 0; devnum < numDevs; devnum++)
    {
        Status = CyGetDeviceInfo(
            devnum,                         /*Device number of the device of interest*/
            &deviceInfo                  /*Info of device returned*/
        );
        for (int dtype = 0; dtype < deviceInfo.numInterfaces; dtype++) {
            if (deviceInfo.deviceType[dtype] == CY_TYPE_SPI) {
                findSPI = true;
                Status = CyOpen(devnum, dtype, &s_SpiHandle);
                break;
            }
        }
        if (findSPI) {
            break;
        }

    }
    

    
    if (Status != CY_SUCCESS)
    {
        return false;
    }

    Status = CyGetSpiConfig(s_SpiHandle, &SpiConfig);
    if (Status != CY_SUCCESS)
    {
        //printf("Connect to spi Error %d!!! \n", Status);
        return false;
    }

    SpiConfig.dataWidth = 8;
    SpiConfig.frequency = SPI_CLOCK_FREQUENCY_HZ;
    SpiConfig.isContinuousMode = true;
    SpiConfig.isCpha = false;
    SpiConfig.isCpol = false;
    SpiConfig.isMaster = true;
    SpiConfig.isMsbFirst = true;
    SpiConfig.isSelectPrecede = false;
    SpiConfig.protocol = CY_SPI_MOTOROLA;


    //SpiConfig = SpiConfig1;
    Status = CySetSpiConfig(s_SpiHandle, &SpiConfig);
    if (Status != CY_SUCCESS)
    {
        //printf("Connect to spi Error %d!!! \n", Status);
        return false;
    }

    Status = CyGetSpiConfig(s_SpiHandle, &SpiConfig2);
    if (Status != CY_SUCCESS)
    {
        //printf("Connect to spi Error %d!!! \n", Status);
        return false;
    }

    BOOL SlaveOperation = false;
    uint8_t Value = 0;


    if (!CYPRESS_SPI_SetCyGpio(Gpio7, 1))
    {
        //printf("Request I2C Start Error \n");
        return false;
    }


    uint8_t GPIO2 = SlaveOperation ? Gpio14 : Gpio8;

    if (!CYPRESS_SPI_GetCyGpio(Gpio7, &Value))
    {
        return false;
    }

    if (Value == 1)
    {

        if (!CYPRESS_SPI_SetCyGpio(GPIO2, 0))
        {
            return false;
        }
        if (!CYPRESS_SPI_GetCyGpio(GPIO2, &Value))
        {
            return false;
        }

    }


    CY_DATA_BUFFER   ReadBuffer, WriteBuffer;

    UINT32 num = 1;
    UCHAR buf[] = { 0x05,0x00 };
    ReadBuffer.buffer = buf;
    ReadBuffer.length = num;
    ReadBuffer.transferCount = 0;

    WriteBuffer.buffer = buf;
    WriteBuffer.length = num;
    WriteBuffer.transferCount = 0;

    Status = CySpiReadWrite(s_SpiHandle,
        &ReadBuffer,
        &WriteBuffer,
        TIMEOUT_MILLISECONDS);
    printf("status:%d\n", Status);
    if ((Status != CY_SUCCESS) && (Status != CY_ERROR_IO_TIMEOUT))
    {

        return false;
    }


    return true;
}

 

0 Likes
Meghavi
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 10 likes received

Hi,

In order to analyze the problem, we will require some more details. Please provide us the following details:

  1. Can you let us know if you are using the CYUSBS236 DVK or any custom board?
  2. Also, please check the library which you are using is latest.

Regards

0 Likes
Jungle
Level 1
Level 1
First reply posted First question asked Welcome!

Hi Meghavi,

1. We refer to TI's DLP EVM implementation board. I2C and SPI communication are carried through CY7C65215-32LTXI chip. On Ubuntu, we could call the API in libcyusbserial.so to control I2C access to data. The dependencies were successfully installed?

2.We update through cypress update manager, and the prompt is up to date.

Do you have an example of operating SPI under Ubuntu?

Regards

0 Likes
Meghavi
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 10 likes received

Hi,

You can refer the SPI example from USB Serial SDK . The example is located at "C:\<Extracted Folder>\USB-Serial SDK\linux_driver\CyUSBSerial_SDK_Linux\linux\library". Please let us know if any other queries.

Regards

0 Likes