完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我想问一下。 首先,我通过软件“USB串行配置实用程序”将这三个芯片cy7c65211A的序列号分别设置为001,002,003。 这三款芯片的 VID 和 PID 是相同的。 然后使用 cyOpen 功能通过 PC 打开设备进行操作;我的 PC 电脑的编程思路是:成功打开设备后,通过识别不同的序列号,不同序列号的灯的闪烁频率不同,最终结果发现灯的闪烁频率是一样的,原因是什么? 应该连接的三个cy7c65211A芯片不应该都使用通过 USB编程的API功能执行相同的操作和访问吗? 当你有时间帮忙回答时,谢谢,祝你工作顺利。 |
|
相关推荐
1个回答
|
|
请根据序列号字符串使用随附的代码进行访问。
此代码在 3 个设备上进行了测试,从设备为 EEPROM。 根据您的要求更改频率和其他参数。 谢谢 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#### /license/license.txt#### where is the Cypress software## installation root directory path.#### ===========================*/// spimaster.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include #include #include #include #include "......librarycyusbserialCyUSBSerial.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 deviceCY_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.hCY_VID_PID cyVidPid;//Variables used by applicationUINT8 cyNumDevices;unsigned char deviceID[16];/** ****************Functions*** **************** */ /*Function Name: CY_RETURN_STATUS cySPIWriteEnable (CY_HANDLE cyHandle)Purpose: Function to send Write Enable command to SPIArguments:cyHandle - cyHandle of the deviceRetrun 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 statusArguments:cyHandle - cyHandle of the deviceRetrun 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 operationsArguments:deviceNumber - The device number identified during the enumeration processRetrun 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 %dn", 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: NoneRetrun 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 accessn"); scanf("%s", serial_number); int deviceIndexAtSCB0 = -1; for (int index = 0; index < cyNumDevices; index++){ printf ("nNumber of interfaces: %dn Vid: 0x%X n Pid: 0x%X n Serial name is: %sn Manufacturer name: %sn Product Name: %sn SCB Number: 0x%X n Device Type: %d n Device Class: %dnnn", 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; } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
5671 浏览 1 评论
摩尔斯微电子推出社区论坛与开源GitHub资源库,新资源的上线将加速全球工程师与开发者的Wi-Fi开发进程
1720 浏览 0 评论
9127 浏览 1 评论
9650 浏览 0 评论
32611 浏览 3 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-3-28 05:14 , Processed in 0.592194 second(s), Total 71, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191