How do I get 400Khz i2c module operation?

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

cross mob
Anonymous
Not applicable


Description Hello? 
I'd like to get 400Khz i2c module operation in the FX3. 

as the below is my i2c code, Can you let me know what am I supposed to do to get the 400KHZ i2c operation? 

////////////////////////////////////////////////////////////// 
/* I2c initialization for EEPROM programming. */ 
CyU3PReturnStatus_t 
CyFxI2cInit (uint16_t pageLen) 

CyU3PI2cConfig_t i2cConfig; 
//CyU3PDmaChannelConfig_t dmaConfig; 
CyU3PReturnStatus_t status = CY_U3P_SUCCESS; 

/* Initialize and configure the I2C master module. */ 
status = CyU3PI2cInit (); 
if (status != CY_U3P_SUCCESS) 

CyU3PDebugPrint (4, "I2C configuration failed!\n"); 
return status; 


/* Start the I2C master block. The bit rate is set at 100KHz. 
* The data transfer is done via DMA. */ 
CyU3PMemSet ((uint8_t *)&i2cConfig, 0, sizeof(i2cConfig)); 
i2cConfig.bitRate = 100000;//CY_FX_USBI2C_I2C_BITRATE; 
i2cConfig.busTimeout = 0xFFFFFFFF; 
i2cConfig.dmaTimeout = 0xFFFF; 
i2cConfig.isDma = CyFalse; 

status = CyU3PI2cSetConfig (&i2cConfig, NULL); 
if (status != CY_U3P_SUCCESS) 

CyU3PDebugPrint (4, "I2C configuration failed!\n"); 
return status; 


/* Now create the DMA channels required for read and write. */ 
//CyU3PMemSet ((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig)); 
//dmaConfig.size = pageLen; 
/* No buffers need to be allocated as this will be used 
* only in override mode. */ 
/* 
dmaConfig.count = 0; 
dmaConfig.prodAvailCount = 0; 
dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE; 
dmaConfig.prodHeader = 0; 
dmaConfig.prodFooter = 0; 
dmaConfig.consHeader = 0; 
dmaConfig.notification = 0; 
dmaConfig.cb = NULL; 
*/ 
/* Create a channel to write to the EEPROM. */ 
/* 
dmaConfig.prodSckId = CY_U3P_CPU_SOCKET_PROD; 
dmaConfig.consSckId = CY_U3P_LPP_SOCKET_I2C_CONS; 
status = CyU3PDmaChannelCreate (&glI2cTxHandle, 
CY_U3P_DMA_TYPE_MANUAL_OUT, &dmaConfig); 
if (status != CY_U3P_SUCCESS) 

return status; 

*/ 
/* Create a channel to read from the EEPROM. */ 
/* 
dmaConfig.prodSckId = CY_U3P_LPP_SOCKET_I2C_PROD; 
dmaConfig.consSckId = CY_U3P_CPU_SOCKET_CONS; 
status = CyU3PDmaChannelCreate (&glI2cRxHandle, 
CY_U3P_DMA_TYPE_MANUAL_IN, &dmaConfig); 

if (status == CY_U3P_SUCCESS) 

glI2cPageSize = pageLen; 

*/ 
return status; 

////////////////////////////////////////////////////////////// 
CyU3PReturnStatus_t 
CyFxUsbI2cTransfer ( 
uint16_t byteAddress, 
uint8_t devAddr, 
uint16_t byteCount, 
uint8_t *buffer, 
CyBool_t isRead) 

CyU3PDmaBuffer_t buf_p; 
CyU3PI2cPreamble_t preamble; 
uint16_t pageCount = (byteCount / glI2cPageSize); 
CyU3PReturnStatus_t status = CY_U3P_SUCCESS; 

if (byteCount == 0) 

return CY_U3P_SUCCESS; 


if ((byteCount % glI2cPageSize) != 0) 

pageCount ++; 


CyU3PDebugPrint (2, "I2C access - dev: 0x%x, address: 0x%x, size: 0x%x, pages: 0x%x.\r\n", 
devAddr, byteAddress, byteCount, pageCount); 

/* Update the buffer address. */ 
buf_p.buffer = buffer; 
buf_p.status = 0; 

while (pageCount != 0) 

if (isRead) 

/* Update the preamble information. */ 
preamble.length = 4; 
preamble.buffer[0] = devAddr; 
preamble.buffer[1] = (uint8_t)(byteAddress >> 8); 
preamble.buffer[2] = (uint8_t)(byteAddress & 0xFF); 
preamble.buffer[3] = (devAddr | 0x01); 
preamble.ctrlMask = 0x0004; 

buf_p.size = glI2cPageSize; 
buf_p.count = glI2cPageSize; 

status = CyU3PI2cSendCommand (&preamble, glI2cPageSize, CyTrue); 
if (status != CY_U3P_SUCCESS) 

return status; 

status = CyU3PDmaChannelSetupRecvBuffer (&glI2cRxHandle, &buf_p); 
if (status != CY_U3P_SUCCESS) 

return status; 

status = CyU3PDmaChannelWaitForCompletion(&glI2cRxHandle, 
CY_FX_USB_I2C_TIMEOUT); 
if (status != CY_U3P_SUCCESS) 

return status; 


else /* Write */ 

/* Update the preamble information. */ 
preamble.length = 3; 
preamble.buffer[0] = devAddr; 
preamble.buffer[1] = (uint8_t)(byteAddress >> 8); 
preamble.buffer[2] = (uint8_t)(byteAddress & 0xFF); 
preamble.ctrlMask = 0x0000; 

buf_p.size = glI2cPageSize; 
buf_p.count = (byteCount > glI2cPageSize) ? glI2cPageSize : byteCount; 

status = CyU3PDmaChannelSetupSendBuffer (&glI2cTxHandle, 
&buf_p); 
if (status != CY_U3P_SUCCESS) 

return status; 

status = CyU3PI2cSendCommand (&preamble, ((byteCount > glI2cPageSize) ? glI2cPageSize : byteCount), CyFalse); 
if (status != CY_U3P_SUCCESS) 

return status; 

status = CyU3PDmaChannelWaitForCompletion(&glI2cTxHandle, 
CY_FX_USB_I2C_TIMEOUT); 
if (status != CY_U3P_SUCCESS) 

return status; 



/* Update the parameters */ 
byteAddress += glI2cPageSize; 
buf_p.buffer += glI2cPageSize; 
byteCount -= glI2cPageSize; 
pageCount --; 

/* Need a delay between write operations. */ 
CyU3PThreadSleep (10); 


return CY_U3P_SUCCESS; 


/////////////////////////////////////////////////////////////

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

The voltage connected to C11 pin of FX3 BGA chip is called VIO 5. This voltage will be used for I2C Master operation. Refer CYUSB3KIT-003 schematic.

   

If you want to configure I2C at 400 kHz, just change the "i2cConfig.bitRate = 100000" to "i2cConfig.bitRate = 400000" in your code and connect VIO5 to 1.8 V, 2.5 V, or 3.3 V.

View solution in original post

0 Likes
9 Replies
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

The default image file built in SDK make sure that I2C works at 400 kHz. There is nothing to do in the FW to make I2C EEPROM to work at 400 kHz. Refer readme.txt in the FX3 SDK directory: C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\util\elf2img

   

Note that when VIO5 is 1.2 V, the maximum operating frequency supported is 100 kHz. When VIO5 is 1.8 V, 2.5 V, or 3.3 V, the operating frequencies supported are 400 kHz and 1 MHz. (VIO5 is the I/O voltage for I2C interface). 

   

What is the operating frequency in your case now?

   

What is the voltage connected to VIO5?

0 Likes
Anonymous
Not applicable

I'm not sure what exactly you are say the operating frequency. but In my case, I'm using slavefifo mode with FPGA. and the FX3 receive the frequency as 100Mhz from FPGA. 

   

and can you let me know where is VIO5? how do I prove where VIO5 is there in FX3? would you please let me know?

   

 

   

 

   

and I found some I2C setting at the code,

   


   

/* Start the I2C master block. The bit rate is set at 100KHz. 
* The data transfer is done via DMA. */ 
CyU3PMemSet ((uint8_t *)&i2cConfig, 0, sizeof(i2cConfig)); 
i2cConfig.bitRate = 100000;//CY_FX_USBI2C_I2C_BITRATE; 
i2cConfig.busTimeout = 0xFFFFFFFF; 
i2cConfig.dmaTimeout = 0xFFFF; 
i2cConfig.isDma = CyFalse; 

   

 

   

doesn't this mean 100KHz?

   

Can you help me how do I check what I use operating frequency?

   

Also can you let me know how do I check what voltage where VIO5 connect?

0 Likes

Yes, it means I2C is configured for 100 kHz.

   

Probe I2C SCL line (D9 in BGA part, D6 in WLCSP part) to know I2C operating frequency.

0 Likes
lock attach
Attachments are accessible only for community members.
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

The voltage connected to C11 pin of FX3 BGA chip is called VIO 5. This voltage will be used for I2C Master operation. Refer CYUSB3KIT-003 schematic.

   

If you want to configure I2C at 400 kHz, just change the "i2cConfig.bitRate = 100000" to "i2cConfig.bitRate = 400000" in your code and connect VIO5 to 1.8 V, 2.5 V, or 3.3 V.

0 Likes
Anonymous
Not applicable

I'd like to connect VIO5 to  3.3 V for using 400Khz I2C in the CYUSB3KIT-003.

   

if you can, can you let me know where does it find in there?

   

is there some kind of jumper pin?

   

if you can please clraify where I can find it from CYUSB3KIT-003?

   

And I also saw that in the schematic, C11 looks already connected by 3.3V. Am I wrong?

   

Can you make clraify this?

0 Likes

Yes, I2C EEPROM is connected 3.3 V (VIO5) in CYUSB3KIT-003. There is no jumper for this.

   

It is expected that I2C communication should happen at 400 kHz when you change the "i2cConfig.bitRate = 100000" to "i2cConfig.bitRate = 400000 in your code.

   

Isn't working at 400 kHz?

0 Likes
Anonymous
Not applicable

Thanks for letting me know that, I'll check it more.

   

BTW, is that support on the 1Mhz? if can, can I just do " "i2cConfig.bitRate = 1000000"?

0 Likes

Yes, it does work at 1 MHz with i2cConfig.bitRate = 1000000.

0 Likes
Anonymous
Not applicable

working good thx

0 Likes