cy7c65211A mutil communicate error

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

cross mob
myzxc
Level 3
Level 3
First solution authored 50 sign-ins 25 replies posted

myzxc_0-1689816890030.png

Hello, I would like to ask. First, I set the Serial number of these three chips cy7c65211A to 001,002,003 respectively through the software "USB Serial Configuration Utility". VID and PID of these three chips are the same. Then open the device through PC using CyOpen function for operation; The programming idea of my PC computer is: after successfully turning on the device, by identifying different Serial numbers, the flashing frequency of the lamp with different Serial numbers is different, and the final result is found that the flashing frequency of the lamp is the same, what is the reason? Shouldn't the three cy7c65211A chips that should be connected all perform the same operation and access using API functions programmed via USB? When you have time to help answer, thank you, good luck with your work.

0 Likes
1 Solution
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi Myzxc,

please use the attached code for accessing based on the serial number string.

this code is tested with 3 devices and the slave is EEPROM.

based on your requirement change the frequency and other parameter.

Thank You

Varun Narolkar

/*
## Cypress USB-Serial Windows Example source file (spimaster.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.
##
## ===========================
*/

// spimaster.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 "..\..\..\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 cyHandle; 
//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 cySPIWriteEnable (CY_HANDLE cyHandle)
Purpose: Function to send Write Enable command to SPI

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/


CY_RETURN_STATUS cySPIWriteEnable (CY_HANDLE cyHandle)
    {
    unsigned char wr_data,rd_data;
    CY_RETURN_STATUS status = CY_SUCCESS;
    CY_DATA_BUFFER writeBuf;
    CY_DATA_BUFFER readBuf;

    printf("\nSending SPI Write Enable command to device...");
    writeBuf.buffer = &wr_data;
    writeBuf.length = 1;

    readBuf.buffer = &rd_data;
    readBuf.length = 1;

    wr_data = 0x06; /* Write enable command*/

    status = CySpiReadWrite (cyHandle, &readBuf,&writeBuf, 5000);
    if (status != CY_SUCCESS)
        {
        printf("\nFailed to send SPI Write Enable command to device.");
        return status;
        }    
    printf("\nSPI Write Enable command sent successfully.");
    return status;

    }



/*
Function Name: CY_RETURN_STATUS cySPIWaitForIdle (CY_HANDLE cyHandle)
Purpose: Function to check for SPI status

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/

CY_RETURN_STATUS cySPIWaitForIdle (CY_HANDLE cyHandle)
    {
    char rd_data[2], wr_data[2];
    CY_DATA_BUFFER writeBuf, readBuf;
    int timeout = 0xFFFF;
    CY_RETURN_STATUS status;


    printf("\nSending SPI Status query command to device...");
    writeBuf.length = 2;
    writeBuf.buffer = (unsigned char *)wr_data;

    readBuf.length = 2;
    readBuf.buffer = (unsigned char *)rd_data;

    // Loop here till read data indicates SPI status is not idle
    // Condition to be checked: rd_data[1] & 0x01

    do
        {
        wr_data[0] = 0x05; /* Get SPI status */
        status = CySpiReadWrite (cyHandle, &readBuf, &writeBuf, 5000);

        if (status != CY_SUCCESS)
            {
            printf("\nFailed to send SPI status query command to device.");
            break;
            }
        timeout--;
        if (timeout == 0)
            {
            printf("\nMaximum retries completed while checking SPI status, returning with error code.");
            status = CY_ERROR_IO_TIMEOUT;
            return status;
            }

        } while (rd_data[1] & 0x01); //Check SPI Status

        printf("\nSPI is now in idle state and ready for receiving additional data commands.");
        return status;
    }


/*
Function Name: int SPIMaster(int deviceNumber)
Purpose: Demonstates how to communicate with EEPROM connected on USB Serial DVK to SPI
- Demonstrates how to set/get configuration of SPI 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, -1 for local failures.
*/


int SPIMaster(int deviceNumber)
    {   
    CY_SPI_CONFIG cySPIConfig,cySpiConfigRestore;
    CY_DATA_BUFFER cyDatabufferWrite,cyDatabufferRead;    
    CY_RETURN_STATUS rStatus;
    int interfaceNum = 0;

    unsigned char wbuffer[4096], rbuffer[4096];

    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260;

    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260;


    memset (rbuffer, 0x00, 4096);
    memset (wbuffer, 0x00, 4096);

    printf ("Opening SPI device with device number %d...\n", deviceNumber);    

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

    if (rStatus != CY_SUCCESS){
        printf ("SPI Device open failed.\n");
        return rStatus;
        }

    printf ("SPI Open successfull. Invoking API for retrieving SPI configuration...\n");

    rStatus = CyGetSpiConfig (cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS){
        printf ("CyGetSpiConfig returned failure code.\n");
        return rStatus;
        }
    printf ("SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    //Configure SPI with new configuration
    printf("\nSetting new SPI configuration...\n");

    cySpiConfigRestore = cySPIConfig;

    cySPIConfig.frequency = 3000000;
    cySPIConfig.dataWidth = 8;
    cySPIConfig.protocol = CY_SPI_MOTOROLA;
    cySPIConfig.isContinuousMode = 1;
    cySPIConfig.isMsbFirst = true;
    cySPIConfig.isMaster = true;
    cySPIConfig.isSelectPrecede = false;  


    printf ("New SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    rStatus = CySetSpiConfig (cyHandle, &cySPIConfig);

    if (rStatus != CY_SUCCESS){
        printf ("CySetSpiConfig returned failure code.\n");
        return rStatus;
        }
    printf("Setting new SPI configuration successful.\n");

    // Check to see if the new configuration is applied on SPI
    printf("Checking the new SPI configuration ...\n");

    rStatus = CyGetSpiConfig (cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS){
        printf ("CyGetSpiConfig returned failure code.\n");
        return rStatus;
        }

    printf ("SPI CONFIG retrieved: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    rStatus = CySetSpiConfig (cyHandle, &cySpiConfigRestore);

    if (rStatus != CY_SUCCESS){
        printf ("CySetSpiConfig restore returned with failure code.\n");
        return rStatus;
        }


    // SPI Read/Write Operations    

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle (cyHandle); 
    if (rStatus){
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);            

        return rStatus;
        }

    printf("EEPROM Write enable ...");
    rStatus =  cySPIWriteEnable (cyHandle);
    if (rStatus){
        printf("Error in setting Write Enable:0x%X \n", rStatus);            
        return rStatus;
        }

    printf("Performing EEPROM Write operation...");

    //Fille the write buffer
    memset (wbuffer, 0xAA, 4096);
    memset (rbuffer, 0x00, 4096);


    //SPI uses a single CySpiReadWrite to perform both read and write 
    //and flush operations.       
    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260; //4 bytes command + 256 bytes page size

    // These values are based on the DVK EEPROM
    wbuffer[0] = 0x02;   // SPI Write command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    // Fill the data buffer
    for (unsigned int index = 4; index < cyDatabufferWrite.length ; index++){
        wbuffer[index] = index;			
        }

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite (cyHandle ,&cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS){           

        printf ("Error in doing SPI data write :0x%X \n" , cyDatabufferWrite.transferCount);
        return rStatus;    
        } 

    printf ("Completed SPI write transfer with %d bytes %d\n", 256);


    printf("Performing EEPROM Read operation...");
    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260; //Page size

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle (cyHandle); 
    if (rStatus){
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);            

        return rStatus;
        }

    // These values are based on the DVK EEPROM
    // In this case the first 4 bytes of WriteBuffer has valid command data.
    wbuffer[0] = 0x03;   //SPI Read command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    memset (&rbuffer[4], 0, 512);

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite (cyHandle, &cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS){
        printf ("CySpiReadWrite returned failure code during read operation.\n");
        return -1;
        }
    printf ("Completed SPI read successfully. Performing data verification...\n");

    if (memcmp(&wbuffer[4],&rbuffer[4],256) == 0)
        {
        printf ("Data verified successfully. \n");
        return CY_SUCCESS;
        }
    else
        {
        printf ("Data verification failied. \n");
        return -1;
        }

    return CY_SUCCESS;

    }

/*
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
    UCHAR serial_number[256] = { 0 };
    //Array size of cyDeviceInfoList is 16 
    cyReturnStatus = CyGetDeviceInfoVidPid (cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
    printf("Enter serial number you want to access\n");
    
    scanf("%s",&serial_number);
    
    int deviceIndexAtSCB0 = -1;
    for (int index = 0; index < cyNumDevices; index++){                
        printf ("\nNumber of interfaces: %d\n \
                Vid: 0x%X \n\
                Pid: 0x%X \n\
                Serial name is: %s\n\
                Manufacturer name: %s\n\
                Product Name: %s\n\
                SCB Number: 0x%X \n\
                Device Type: %d \n\
                Device Class: %d\n\n\n",
                cyDeviceInfoList[index].numInterfaces,                  
                cyDeviceInfoList[index].vidPid.vid,
                cyDeviceInfoList[index].vidPid.pid,
                cyDeviceInfoList[index].serialNum,
                cyDeviceInfoList[index].manufacturerName,
                cyDeviceInfoList[index].productName,
                cyDeviceInfoList[index].deviceBlock,
                cyDeviceInfoList[index].deviceType[0],
                cyDeviceInfoList[index].deviceClass[0]);
        
        // Find the device at device index at SCB0
        if (cyDeviceInfoList[index].deviceBlock == SerialBlock_SCB0)
            {
           if(strcmp((const char*)cyDeviceInfoList[index].serialNum, (const char*)serial_number)== 0)
            deviceIndexAtSCB0 = index;
            }
        }
    return deviceIndexAtSCB0;
    }

/** ********************************
Application main() function
*** ******************************** */     


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


    //Assmumptions:
    //1. SCB0 is configured as UART     
    int deviceIndexAtSCB0 = FindDeviceAtSCB0();

    //Open the device at index deviceIndexAtSCB0
    if (deviceIndexAtSCB0 >= 0)
        {


        //Assuming that USB-Serial at "deviceIndexAtSCB0" is configured as SPI device
        //Device Open, Close, Configuration, Data operations are handled in the function SPIMaster

        int status = SPIMaster(deviceIndexAtSCB0);

        if (status == 0)
            {
            printf("\nSPIMaster returned success.\n");
            }
        else
            {
            printf("\nSPIMaster returned failure code.\n");
            }

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

    return 0;
    }

 

View solution in original post

0 Likes
15 Replies
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi Myzxc,

please share your code if it is not confidential we will check and update you

please share files you are .cyusb file you are flashing .

Thank You

Varun Narolkar

0 Likes
lock attach
Attachments are accessible only for community members.
myzxc
Level 3
Level 3
First solution authored 50 sign-ins 25 replies posted

Hello, thank you for your reply, I hope you can answer, thank you, I wish the work is smooth.

 

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi myzxc ,

you are calling CySetSpiConfig() in SPIMaster() function as per your application you have to change the frequency as per your requirement or else it will take default frequency and configuration as mentioned below.

cySPIConfig.frequency = 1000000;
cySPIConfig.dataWidth = 8;
cySPIConfig.protocol = CY_SPI_MOTOROLA;
cySPIConfig.isContinuousMode = 1;
cySPIConfig.isMsbFirst = true;
cySPIConfig.isMaster = true;
cySPIConfig.isSelectPrecede = false;
rStatus = CySetSpiConfig (cyHandle, &cySPIConfig);

Thank you

Varun Narolkar

0 Likes

你好,感谢你的回复,你的意思是不是说虽然我通过"cy7c65211-spi.cyusb"这个文件对cy7c65211A芯片进行烧写了SPI的配置,但实际上如果想使用PC电脑调用API时,还是需要通过CySetSpiConfig()函数再次配置下SPI,否则当前的SPI配置还是默认值。然后我想知道这个会影响到我对GPIO的操作吗,根据现象看,好像并没有影响,能否用我的测试代码帮忙测试下看能否达到通过Serial number区分两块cy7c65211A芯片,达到实现灯的不同闪烁频率,GPIO11是板子上的一个led,低电平有效,希望尽快帮忙解答下,谢谢,祝工作顺利。

myzxc_0-1689899887494.png

 

0 Likes
myzxc
Level 3
Level 3
First solution authored 50 sign-ins 25 replies posted

Hello, thank you for your reply. Do you mean to say that although I have burned the SPI configuration of the cy7c65211A chip through the file "cy7c65211-spi.cyusb", in fact, if I want to use the PC to call the API, It is still necessary to configure the SPI again through the CySetSpiConfig() function, otherwise the current SPI configuration is still the default value. Then I want to know whether this will affect my operation of GPIO. According to the phenomenon, it doesn't seem to have any effect. Could you please use my test code to help test whether two cy7c65211A chips can be distinguished by Serial number to achieve different flashing frequencies of lights? GPIO11 is an led on the board, the low level is effective, hope to help answer as soon as possible, thank you, I wish the work is smooth.

myzxc_0-1690159060806.png

 

0 Likes

Hello, thank you for your reply. Do you mean to say that although I have burned the SPI configuration of the cy7c65211A chip through the file "cy7c65211-spi.cyusb", in fact, if I want to use the PC to call the API, It is still necessary to configure the SPI again through the CySetSpiConfig() function, otherwise the current SPI configuration is still the default value. Then I want to know whether this will affect my operation of GPIO. According to the phenomenon, it doesn't seem to have any effect. Could you please use my test code to help test whether two cy7c65211A chips can be distinguished by Serial number to achieve different flashing frequencies of lights? GPIO11 is an led on the board, the low level is effective, hope to help answer as soon as possible, thank you, I wish the work is smooth.

myzxc_0-1690159303017.png

 

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi Myzxc,

please use the attached code for accessing based on the serial number string.

this code is tested with 3 devices and the slave is EEPROM.

based on your requirement change the frequency and other parameter.

Thank You

Varun Narolkar

/*
## Cypress USB-Serial Windows Example source file (spimaster.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.
##
## ===========================
*/

// spimaster.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 "..\..\..\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 cyHandle; 
//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 cySPIWriteEnable (CY_HANDLE cyHandle)
Purpose: Function to send Write Enable command to SPI

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/


CY_RETURN_STATUS cySPIWriteEnable (CY_HANDLE cyHandle)
    {
    unsigned char wr_data,rd_data;
    CY_RETURN_STATUS status = CY_SUCCESS;
    CY_DATA_BUFFER writeBuf;
    CY_DATA_BUFFER readBuf;

    printf("\nSending SPI Write Enable command to device...");
    writeBuf.buffer = &wr_data;
    writeBuf.length = 1;

    readBuf.buffer = &rd_data;
    readBuf.length = 1;

    wr_data = 0x06; /* Write enable command*/

    status = CySpiReadWrite (cyHandle, &readBuf,&writeBuf, 5000);
    if (status != CY_SUCCESS)
        {
        printf("\nFailed to send SPI Write Enable command to device.");
        return status;
        }    
    printf("\nSPI Write Enable command sent successfully.");
    return status;

    }



/*
Function Name: CY_RETURN_STATUS cySPIWaitForIdle (CY_HANDLE cyHandle)
Purpose: Function to check for SPI status

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/

CY_RETURN_STATUS cySPIWaitForIdle (CY_HANDLE cyHandle)
    {
    char rd_data[2], wr_data[2];
    CY_DATA_BUFFER writeBuf, readBuf;
    int timeout = 0xFFFF;
    CY_RETURN_STATUS status;


    printf("\nSending SPI Status query command to device...");
    writeBuf.length = 2;
    writeBuf.buffer = (unsigned char *)wr_data;

    readBuf.length = 2;
    readBuf.buffer = (unsigned char *)rd_data;

    // Loop here till read data indicates SPI status is not idle
    // Condition to be checked: rd_data[1] & 0x01

    do
        {
        wr_data[0] = 0x05; /* Get SPI status */
        status = CySpiReadWrite (cyHandle, &readBuf, &writeBuf, 5000);

        if (status != CY_SUCCESS)
            {
            printf("\nFailed to send SPI status query command to device.");
            break;
            }
        timeout--;
        if (timeout == 0)
            {
            printf("\nMaximum retries completed while checking SPI status, returning with error code.");
            status = CY_ERROR_IO_TIMEOUT;
            return status;
            }

        } while (rd_data[1] & 0x01); //Check SPI Status

        printf("\nSPI is now in idle state and ready for receiving additional data commands.");
        return status;
    }


/*
Function Name: int SPIMaster(int deviceNumber)
Purpose: Demonstates how to communicate with EEPROM connected on USB Serial DVK to SPI
- Demonstrates how to set/get configuration of SPI 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, -1 for local failures.
*/


int SPIMaster(int deviceNumber)
    {   
    CY_SPI_CONFIG cySPIConfig,cySpiConfigRestore;
    CY_DATA_BUFFER cyDatabufferWrite,cyDatabufferRead;    
    CY_RETURN_STATUS rStatus;
    int interfaceNum = 0;

    unsigned char wbuffer[4096], rbuffer[4096];

    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260;

    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260;


    memset (rbuffer, 0x00, 4096);
    memset (wbuffer, 0x00, 4096);

    printf ("Opening SPI device with device number %d...\n", deviceNumber);    

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

    if (rStatus != CY_SUCCESS){
        printf ("SPI Device open failed.\n");
        return rStatus;
        }

    printf ("SPI Open successfull. Invoking API for retrieving SPI configuration...\n");

    rStatus = CyGetSpiConfig (cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS){
        printf ("CyGetSpiConfig returned failure code.\n");
        return rStatus;
        }
    printf ("SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    //Configure SPI with new configuration
    printf("\nSetting new SPI configuration...\n");

    cySpiConfigRestore = cySPIConfig;

    cySPIConfig.frequency = 3000000;
    cySPIConfig.dataWidth = 8;
    cySPIConfig.protocol = CY_SPI_MOTOROLA;
    cySPIConfig.isContinuousMode = 1;
    cySPIConfig.isMsbFirst = true;
    cySPIConfig.isMaster = true;
    cySPIConfig.isSelectPrecede = false;  


    printf ("New SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    rStatus = CySetSpiConfig (cyHandle, &cySPIConfig);

    if (rStatus != CY_SUCCESS){
        printf ("CySetSpiConfig returned failure code.\n");
        return rStatus;
        }
    printf("Setting new SPI configuration successful.\n");

    // Check to see if the new configuration is applied on SPI
    printf("Checking the new SPI configuration ...\n");

    rStatus = CyGetSpiConfig (cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS){
        printf ("CyGetSpiConfig returned failure code.\n");
        return rStatus;
        }

    printf ("SPI CONFIG retrieved: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode); 

    rStatus = CySetSpiConfig (cyHandle, &cySpiConfigRestore);

    if (rStatus != CY_SUCCESS){
        printf ("CySetSpiConfig restore returned with failure code.\n");
        return rStatus;
        }


    // SPI Read/Write Operations    

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle (cyHandle); 
    if (rStatus){
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);            

        return rStatus;
        }

    printf("EEPROM Write enable ...");
    rStatus =  cySPIWriteEnable (cyHandle);
    if (rStatus){
        printf("Error in setting Write Enable:0x%X \n", rStatus);            
        return rStatus;
        }

    printf("Performing EEPROM Write operation...");

    //Fille the write buffer
    memset (wbuffer, 0xAA, 4096);
    memset (rbuffer, 0x00, 4096);


    //SPI uses a single CySpiReadWrite to perform both read and write 
    //and flush operations.       
    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260; //4 bytes command + 256 bytes page size

    // These values are based on the DVK EEPROM
    wbuffer[0] = 0x02;   // SPI Write command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    // Fill the data buffer
    for (unsigned int index = 4; index < cyDatabufferWrite.length ; index++){
        wbuffer[index] = index;			
        }

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite (cyHandle ,&cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS){           

        printf ("Error in doing SPI data write :0x%X \n" , cyDatabufferWrite.transferCount);
        return rStatus;    
        } 

    printf ("Completed SPI write transfer with %d bytes %d\n", 256);


    printf("Performing EEPROM Read operation...");
    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260; //Page size

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle (cyHandle); 
    if (rStatus){
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);            

        return rStatus;
        }

    // These values are based on the DVK EEPROM
    // In this case the first 4 bytes of WriteBuffer has valid command data.
    wbuffer[0] = 0x03;   //SPI Read command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    memset (&rbuffer[4], 0, 512);

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite (cyHandle, &cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS){
        printf ("CySpiReadWrite returned failure code during read operation.\n");
        return -1;
        }
    printf ("Completed SPI read successfully. Performing data verification...\n");

    if (memcmp(&wbuffer[4],&rbuffer[4],256) == 0)
        {
        printf ("Data verified successfully. \n");
        return CY_SUCCESS;
        }
    else
        {
        printf ("Data verification failied. \n");
        return -1;
        }

    return CY_SUCCESS;

    }

/*
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
    UCHAR serial_number[256] = { 0 };
    //Array size of cyDeviceInfoList is 16 
    cyReturnStatus = CyGetDeviceInfoVidPid (cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
    printf("Enter serial number you want to access\n");
    
    scanf("%s",&serial_number);
    
    int deviceIndexAtSCB0 = -1;
    for (int index = 0; index < cyNumDevices; index++){                
        printf ("\nNumber of interfaces: %d\n \
                Vid: 0x%X \n\
                Pid: 0x%X \n\
                Serial name is: %s\n\
                Manufacturer name: %s\n\
                Product Name: %s\n\
                SCB Number: 0x%X \n\
                Device Type: %d \n\
                Device Class: %d\n\n\n",
                cyDeviceInfoList[index].numInterfaces,                  
                cyDeviceInfoList[index].vidPid.vid,
                cyDeviceInfoList[index].vidPid.pid,
                cyDeviceInfoList[index].serialNum,
                cyDeviceInfoList[index].manufacturerName,
                cyDeviceInfoList[index].productName,
                cyDeviceInfoList[index].deviceBlock,
                cyDeviceInfoList[index].deviceType[0],
                cyDeviceInfoList[index].deviceClass[0]);
        
        // Find the device at device index at SCB0
        if (cyDeviceInfoList[index].deviceBlock == SerialBlock_SCB0)
            {
           if(strcmp((const char*)cyDeviceInfoList[index].serialNum, (const char*)serial_number)== 0)
            deviceIndexAtSCB0 = index;
            }
        }
    return deviceIndexAtSCB0;
    }

/** ********************************
Application main() function
*** ******************************** */     


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


    //Assmumptions:
    //1. SCB0 is configured as UART     
    int deviceIndexAtSCB0 = FindDeviceAtSCB0();

    //Open the device at index deviceIndexAtSCB0
    if (deviceIndexAtSCB0 >= 0)
        {


        //Assuming that USB-Serial at "deviceIndexAtSCB0" is configured as SPI device
        //Device Open, Close, Configuration, Data operations are handled in the function SPIMaster

        int status = SPIMaster(deviceIndexAtSCB0);

        if (status == 0)
            {
            printf("\nSPIMaster returned success.\n");
            }
        else
            {
            printf("\nSPIMaster returned failure code.\n");
            }

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

    return 0;
    }

 

0 Likes

Hello, thank you for your reply. Could you please show me the devices in the "Universal Serial Control Bus" in your device Manager and the execution process of your test program?thank you, I wish the work is smooth.

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

HI myzxc,

As shown in the device manager we have connected 3 USB to the serial bridge controller configured as spi master.

narolkarvarun_0-1690349049331.png

Give different serial number to each devices .

as shown below.

narolkarvarun_1-1690349172727.png

after configuring serial number for all devices copy attached spimaster.cpp at below location.

C:\Program Files (x86)\Cypress\USB-Serial SDK\examples\usbserialexample\spimaster

after open this project in visual studio and compile the code.

then run the spi master project you will get list of device connected to the PC.

select specific device you want to access and perform activity as you need.

/*
## Cypress USB-Serial Windows Example source file (spimaster.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.
##
## ===========================
*/

// spimaster.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 "..\..\..\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 cyHandle;
//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 cySPIWriteEnable (CY_HANDLE cyHandle)
Purpose: Function to send Write Enable command to SPI

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/


CY_RETURN_STATUS cySPIWriteEnable(CY_HANDLE cyHandle)
{
    unsigned char wr_data, rd_data;
    CY_RETURN_STATUS status = CY_SUCCESS;
    CY_DATA_BUFFER writeBuf;
    CY_DATA_BUFFER readBuf;

    printf("\nSending SPI Write Enable command to device...");
    writeBuf.buffer = &wr_data;
    writeBuf.length = 1;

    readBuf.buffer = &rd_data;
    readBuf.length = 1;

    wr_data = 0x06; /* Write enable command*/

    status = CySpiReadWrite(cyHandle, &readBuf, &writeBuf, 5000);
    if (status != CY_SUCCESS)
    {
        printf("\nFailed to send SPI Write Enable command to device.");
        return status;
    }
    printf("\nSPI Write Enable command sent successfully.");
    return status;

}



/*
Function Name: CY_RETURN_STATUS cySPIWaitForIdle (CY_HANDLE cyHandle)
Purpose: Function to check for SPI status

Arguments:
cyHandle - cyHandle of the device
Retrun Code: returns falure code of USB-Serial API

*/

CY_RETURN_STATUS cySPIWaitForIdle(CY_HANDLE cyHandle)
{
    char rd_data[2], wr_data[2];
    CY_DATA_BUFFER writeBuf, readBuf;
    int timeout = 0xFFFF;
    CY_RETURN_STATUS status;


    printf("\nSending SPI Status query command to device...");
    writeBuf.length = 2;
    writeBuf.buffer = (unsigned char*)wr_data;

    readBuf.length = 2;
    readBuf.buffer = (unsigned char*)rd_data;

    // Loop here till read data indicates SPI status is not idle
    // Condition to be checked: rd_data[1] & 0x01

    do
    {
        wr_data[0] = 0x05; /* Get SPI status */
        status = CySpiReadWrite(cyHandle, &readBuf, &writeBuf, 5000);

        if (status != CY_SUCCESS)
        {
            printf("\nFailed to send SPI status query command to device.");
            break;
        }
        timeout--;
        if (timeout == 0)
        {
            printf("\nMaximum retries completed while checking SPI status, returning with error code.");
            status = CY_ERROR_IO_TIMEOUT;
            return status;
        }

    } while (rd_data[1] & 0x01); //Check SPI Status

    printf("\nSPI is now in idle state and ready for receiving additional data commands.");
    return status;
}


/*
Function Name: int SPIMaster(int deviceNumber)
Purpose: Demonstates how to communicate with EEPROM connected on USB Serial DVK to SPI
- Demonstrates how to set/get configuration of SPI 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, -1 for local failures.
*/


int SPIMaster(int deviceNumber)
{
    CY_SPI_CONFIG cySPIConfig, cySpiConfigRestore;
    CY_DATA_BUFFER cyDatabufferWrite, cyDatabufferRead;
    CY_RETURN_STATUS rStatus;
    int interfaceNum = 0;

    unsigned char wbuffer[4096], rbuffer[4096];

    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260;

    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260;


    memset(rbuffer, 0x00, 4096);
    memset(wbuffer, 0x00, 4096);

    printf("Opening SPI device with device number %d...\n", deviceNumber);

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

    if (rStatus != CY_SUCCESS) {
        printf("SPI Device open failed.\n");
        return rStatus;
    }

    printf("SPI Open successfull. Invoking API for retrieving SPI configuration...\n");

    rStatus = CyGetSpiConfig(cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS) {
        printf("CyGetSpiConfig returned failure code.\n");
        return rStatus;
    }
    printf("SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode);

    //Configure SPI with new configuration
    printf("\nSetting new SPI configuration...\n");

    cySpiConfigRestore = cySPIConfig;

    cySPIConfig.frequency = 3000000;
    cySPIConfig.dataWidth = 8;
    cySPIConfig.protocol = CY_SPI_MOTOROLA;
    cySPIConfig.isContinuousMode = 1;
    cySPIConfig.isMsbFirst = true;
    cySPIConfig.isMaster = true;
    cySPIConfig.isSelectPrecede = false;


    printf("New SPI CONFIG: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode);

    rStatus = CySetSpiConfig(cyHandle, &cySPIConfig);

    if (rStatus != CY_SUCCESS) {
        printf("CySetSpiConfig returned failure code.\n");
        return rStatus;
    }
    printf("Setting new SPI configuration successful.\n");

    // Check to see if the new configuration is applied on SPI
    printf("Checking the new SPI configuration ...\n");

    rStatus = CyGetSpiConfig(cyHandle, &cySPIConfig);
    if (rStatus != CY_SUCCESS) {
        printf("CyGetSpiConfig returned failure code.\n");
        return rStatus;
    }

    printf("SPI CONFIG retrieved: Frequency Is %d , data width id %d, is continuousmode %d \n", cySPIConfig.frequency, cySPIConfig.dataWidth, cySPIConfig.isContinuousMode);

    rStatus = CySetSpiConfig(cyHandle, &cySpiConfigRestore);

    if (rStatus != CY_SUCCESS) {
        printf("CySetSpiConfig restore returned with failure code.\n");
        return rStatus;
    }


    // SPI Read/Write Operations    

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle(cyHandle);
    if (rStatus) {
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);

        return rStatus;
    }

    printf("EEPROM Write enable ...");
    rStatus = cySPIWriteEnable(cyHandle);
    if (rStatus) {
        printf("Error in setting Write Enable:0x%X \n", rStatus);
        return rStatus;
    }

    printf("Performing EEPROM Write operation...");

    //Fille the write buffer
    memset(wbuffer, 0xAA, 4096);
    memset(rbuffer, 0x00, 4096);


    //SPI uses a single CySpiReadWrite to perform both read and write 
    //and flush operations.       
    cyDatabufferWrite.buffer = wbuffer;
    cyDatabufferWrite.length = 260; //4 bytes command + 256 bytes page size

    // These values are based on the DVK EEPROM
    wbuffer[0] = 0x02;   // SPI Write command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    // Fill the data buffer
    for (unsigned int index = 4; index < cyDatabufferWrite.length; index++) {
        wbuffer[index] = index;
    }

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite(cyHandle, &cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS) {

        printf("Error in doing SPI data write :0x%X \n", cyDatabufferWrite.transferCount);
        return rStatus;
    }

    printf("Completed SPI write transfer with %d bytes %d\n", 256);


    printf("Performing EEPROM Read operation...");
    cyDatabufferRead.buffer = rbuffer;
    cyDatabufferRead.length = 260; //Page size

    printf("Wait for EEPROM active state...");
    rStatus = cySPIWaitForIdle(cyHandle);
    if (rStatus) {
        printf("Error in Waiting for EEPOM active state:0x%X \n", rStatus);

        return rStatus;
    }

    // These values are based on the DVK EEPROM
    // In this case the first 4 bytes of WriteBuffer has valid command data.
    wbuffer[0] = 0x03;   //SPI Read command
    wbuffer[1] = 0x00;   //(startAddress >> 16)&0xFF; //Page address - MSB
    wbuffer[2] = 0x00;   //(startAddress >> 8)&0xFF;  //Page address - MSB
    wbuffer[3] = 0x00;   //(startAddress&0xFF);  // //Page address - LSB

    memset(&rbuffer[4], 0, 512);

    // As per the EEPROM datasheet we need to perform simeltanious read and write
    // to do read/write operation on EEPROM.
    // In this case cyDatabufferRead contains data pushed out by EEPROM and not real data.


    rStatus = CySpiReadWrite(cyHandle, &cyDatabufferRead, &cyDatabufferWrite, 5000);
    if (rStatus != CY_SUCCESS) {
        printf("CySpiReadWrite returned failure code during read operation.\n");
        return -1;
    }
    printf("Completed SPI read successfully. Performing data verification...\n");

    if (memcmp(&wbuffer[4], &rbuffer[4], 256) == 0)
    {
        printf("Data verified successfully. \n");
        return CY_SUCCESS;
    }
    else
    {
        printf("Data verification failied. \n");
        return -1;
    }

    return CY_SUCCESS;

}

/*
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
    UCHAR serial_number[256] = { 0 };
    //Array size of cyDeviceInfoList is 16 
    cyReturnStatus = CyGetDeviceInfoVidPid(cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
    printf("Enter serial number you want to access\n");

    scanf("%s", &serial_number);

    int deviceIndexAtSCB0 = -1;
    for (int index = 0; index < cyNumDevices; index++) {
        printf("\nNumber of interfaces: %d\n \
                Vid: 0x%X \n\
                Pid: 0x%X \n\
                Serial name is: %s\n\
                Manufacturer name: %s\n\
                Product Name: %s\n\
                SCB Number: 0x%X \n\
                Device Type: %d \n\
                Device Class: %d\n\n\n",
            cyDeviceInfoList[index].numInterfaces,
            cyDeviceInfoList[index].vidPid.vid,
            cyDeviceInfoList[index].vidPid.pid,
            cyDeviceInfoList[index].serialNum,
            cyDeviceInfoList[index].manufacturerName,
            cyDeviceInfoList[index].productName,
            cyDeviceInfoList[index].deviceBlock,
            cyDeviceInfoList[index].deviceType[0],
            cyDeviceInfoList[index].deviceClass[0]);

        // Find the device at device index at SCB0
        if (cyDeviceInfoList[index].deviceBlock == SerialBlock_SCB0)
        {
            if (strcmp((const char*)cyDeviceInfoList[index].serialNum, (const char*)serial_number) == 0)
                deviceIndexAtSCB0 = index;
        }
    }
    return deviceIndexAtSCB0;
}

void print_list_of_device(void) {
    CY_VID_PID cyVidPid;

    cyVidPid.vid = VID; //Defined as macro
    cyVidPid.pid = PID; //Defined as macro
    UCHAR serial_number[256] = { 0 };
    //Array size of cyDeviceInfoList is 16 
    cyReturnStatus = CyGetDeviceInfoVidPid(cyVidPid, deviceID, (PCY_DEVICE_INFO)&cyDeviceInfoList, &cyNumDevices, 16);
    //printf("Enter serial number you want to access\n");

    //scanf("%s", &serial_number);

    int deviceIndexAtSCB0 = -1;
    for (int index = 0; index < cyNumDevices; index++) {
        printf("\nNumber of interfaces: %d\n \
                Vid: 0x%X \n\
                Pid: 0x%X \n\
                Serial name is: %s\n\
                Manufacturer name: %s\n\
                Product Name: %s\n\
                SCB Number: 0x%X \n\
                Device Type: %d \n\
                Device Class: %d\n\n\n",
            cyDeviceInfoList[index].numInterfaces,
            cyDeviceInfoList[index].vidPid.vid,
            cyDeviceInfoList[index].vidPid.pid,
            cyDeviceInfoList[index].serialNum,
            cyDeviceInfoList[index].manufacturerName,
            cyDeviceInfoList[index].productName,
            cyDeviceInfoList[index].deviceBlock,
            cyDeviceInfoList[index].deviceType[0],
            cyDeviceInfoList[index].deviceClass[0]);

        // Find the device at device index at SCB0
        
    }
    return ;
}


/** ********************************
Application main() function
*** ******************************** */


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


    //Assmumptions:
    //1. SCB0 is configured as UART   
    print_list_of_device();
    int deviceIndexAtSCB0 = FindDeviceAtSCB0();

    //Open the device at index deviceIndexAtSCB0
    if (deviceIndexAtSCB0 >= 0)
    {


        //Assuming that USB-Serial at "deviceIndexAtSCB0" is configured as SPI device
        //Device Open, Close, Configuration, Data operations are handled in the function SPIMaster

        int status = SPIMaster(deviceIndexAtSCB0);

        if (status == 0)
        {
            printf("\nSPIMaster returned success.\n");
        }
        else
        {
            printf("\nSPIMaster returned failure code.\n");
        }

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

    return 0;
}

 you will get out put as below 

narolkarvarun_2-1690349558014.png

narolkarvarun_3-1690349595126.png

 

Thank you 

Varun Narolkar

 

 

 

0 Likes

Hello, thank you for your reply. What I mean is that the three cy7c65211A chip devices are connected to each other through usb, and then a usb is finally drawn to connect to the computer. Therefore, in the end, only one Vendor 1 is seen in the device manager or only one device is seen in the "USB Serial Configuration Utility" software instead of three devices. Thank you and good luck.

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

hi myzxc, 

clarification here Cy7c65211a is not connected to each other it is connected to Host PC.

narolkarvarun_0-1690354288169.png

Thank You

Varun Narolkar

 

 

0 Likes

Hello, thank you for your reply. I know your practice, so I would like to ask if the cy7c65211A chip devices are connected to each other through usb, whether they can be distinguished by serialNumber,Thank you and good luck.

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi Myzxc ,

below is the one way Cy7c65211A can communicate with each other. you can use i2c master-slave or UART based on your application.

narolkarvarun_0-1690358585062.png

Thank you

Varun Narolkar

0 Likes

Hello, thank you for your reply.I would like to know whether the scheme I have shown below is feasible. Theoretically, there are many cy7c65211A chip devices connected to each other, and each cy7c65211A chip device leads to two identical PORTA (USB interface). In order to facilitate the connection with other cy7c65211A chip devices, Now only three devices are listed as examples, each cy7c65211A chip is connected to the sensor in SPI mode, the purpose is to obtain all the sensor data on the cy7c65211A chip through the PC computer, because multiple cy7c65211A chip devices cannot be distinguished, so the accuracy of the data cannot be guaranteed. Therefore, I hope you can help to test and confirm whether this scheme is feasible. Thank you and wish you success in your work.

myzxc_0-1690361760775.png

 

0 Likes
narolkarvarun
Moderator
Moderator
Moderator
5 likes given 100 solutions authored 250 replies posted

Hi Myzxc,

This, as previously indicated, is not achievable.

check this threadhttps://community.infineon.com/t5/USB-low-full-high-speed/cy7c65211A-multi-usb/m-p/455020#M11753
This event is not supported by USB Device standards.
For more details, 
please check the USB Serial bridge controller (Cy7c65211A) datasheet.

You can use a USB Hub to connect all of your devices to a single port.

Thank you

Varun Narolkar

0 Likes