- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Cypress,
I have CyUSBS236 DVK board and wanted to connect external I2C device to it.
I configured SCB0 to I2C and set SCB0 "jump 17" and "jump 20" to "1 and 2", which means I can connect external device from header pin 5 (GPIO3) and 7 (GPIO4).
My external device address is 0x48, and both SDA and SCL are pulled up to VCC (3.3V).
I first search onboard I2C
rStatus = CyGetListofDevices(&numDevices);
if ((rStatus != CY_SUCCESS) || (numDevices == 0))
{
printf(" Did not get it");
}
for (DeviceIdx = 0; DeviceIdx < numDevices; DeviceIdx++)
{
rStatus = CyGetDeviceInfo(DeviceIdx, &DeviceInfo);
if (rStatus != CY_SUCCESS)
{
continue;
}
for (InterfaceIdx = 0; InterfaceIdx < DeviceInfo.numInterfaces; InterfaceIdx++)
{
if (DeviceInfo.deviceType[InterfaceIdx] == CY_TYPE_I2C)
{
deviceNumber=DeviceIdx;
interfaceNum=InterfaceIdx;
printf("found I2C DeviceIndex: %d, InterfaceIndex: %d \n", DeviceIdx, InterfaceIdx);
}
}
}
rStatus = CyOpen (deviceNumber, interfaceNum, &handle);
if (rStatus != CY_SUCCESS)
{
printf("CY_I2C: Open failed \n");
}
Up to here every thing is ok, but when I
CY_I2C_CONFIG cyI2CConfig;
CY_DATA_BUFFER cyDataBuffer;
CY_I2C_DATA_CONFIG cyI2CDataConfig;
unsigned char readBuffer[4096], writeBuffer[4096];
UINT32 timeout = 5000;
cyI2CDataConfig.slaveAddress = 0x48;
cyI2CDataConfig.isNakBit = true;
cyI2CDataConfig.isStopBit = true;
memset(writeBuffer, 0x00, 4096);
cyDataBuffer.buffer = writeBuffer;
cyDataBuffer.buffer[0] = 0x01;
cyDataBuffer.buffer[1] = 0xc4;
cyDataBuffer.buffer[2] = 0xd3;
cyDataBuffer.length = 3;
rStatus = CyI2cWrite(handle, &cyI2CDataConfig, &cyDataBuffer, timeout);
if (rStatus != CY_SUCCESS)
{
printf("ADC setting fail \n");
}
I got error,
Could anyone give me some advices?
Thank you!
Derlin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Slave address to which the USB-Serial device is communicating with, is stored in the structure CY_I2C_DATA_CONFIG.
If the 7bit address of the slave is 0x48 the set cyI2CDataConfig.slaveAddress = 0x48 (CY_I2C_DATA_CONFIG cyI2CDataConfig).
Return status 17 is a NAK from the slave device. Please check if the slave address is proper.
Best Regards,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Derlin,
Can you please let me know if you are using the I2C example from the SDK.
What is the error code that is returned. You can check it by printing the rStatus or by debugging the application in visual studios using breakpoints.
Best Regards,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Derlin,
Please set the desired I2C configuration for the master using the USB-Serial Configuration Utiltiy.
Best Regards,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh
If I follow the Cypress instructions, set jump 17 and jump 20 to "2 and 3". I have no problem sending and verifying data to EEPROM, which also means that my SCB0 I2C configuration is correct.
But when I set the jump 17 and jump 20 to "1 and 2" and want to use GPIO header GPIO3 and GPIO4 (pin 5 and 7), I can't communicate with external device (address 0x48 with 2.2k pull up resistors).
I tried 0x48 or 0x24, both fail, return value:17.
Any suggestion?
Thanks!
Derlin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Please try left shifting the I2C slave address by one bit (i.e. 0x90) , reason for this is if the slave has a 7 bit slave address then we will send and extra bit while accessing the slave the which might be considered and the slave device will NAK the request.
Also please collect the I2C logs using an analyzer for better debugging the issue.
Best Regards,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Slave address to which the USB-Serial device is communicating with, is stored in the structure CY_I2C_DATA_CONFIG.
If the 7bit address of the slave is 0x48 the set cyI2CDataConfig.slaveAddress = 0x48 (CY_I2C_DATA_CONFIG cyI2CDataConfig).
Return status 17 is a NAK from the slave device. Please check if the slave address is proper.
Best Regards,
Yatheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Yatheesh,
I connected my I2C device (Analog to Digital Converter) on the jump 17 and 20 so they are in parallel with EEPROM. The connection seems ok with address 0x48.
and I do not get error.
cyI2CDataConfig.slaveAddress = 0x48; //DAC address
cyI2CDataConfig.isNakBit = true;
cyI2CDataConfig.isStopBit = true;
cyDataBufferWrite.buffer = writeBuffer;
cyDataBufferWrite.buffer[0] = 0x01; // this is the register of ADC
cyDataBufferWrite.buffer[1] = 0xc4; // this is the configuration
cyDataBufferWrite.buffer[2] = 0xd3; // this is the configuration too
cyDataBufferWrite.length = 3;
rStatus = CyI2cWrite(handle, &cyI2CDataConfig, &cyDataBufferWrite, timeout);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Then I want to read measuring voltage from ADC, the register is 0x00, data length is 2 bytes
memset (readBuffer, 0x00, 4096);
cyI2CDataConfig.isStopBit = true;
cyI2CDataConfig.isNakBit = true;
readBuffer[0]= 0x00; //register
readBuffer[1] = 0; // no meaning
cyDataBufferRead.buffer = readBuffer;
cyDataBufferRead.length = 2;
rStatus = CyI2cRead (handle, &cyI2CDataConfig, &cyDataBufferRead, 5000);
There is no error, but the data is not correct.
Any advise?
Thanks!
Derlin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Derlin,
Can you please let me know what value is expected and what is the actual received value?
Best Regards,
Yatheesh