I2C read deserializer register

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

cross mob
UserP1994
Level 3
Level 3
10 replies posted 10 questions asked 10 sign-ins

Hello, I want to read the deserializer register but it is not working, can someone to help me? Thank you.  With I2C_SLAVE_ADDRESS (0xA0u) is working fine but with deserializer adres (0xA4u)it is not.

 

/*
## Cypress FX3 Boot Firmware Example Source file (main.c)
## ===========================
##
## Copyright Cypress Semiconductor Corporation, 2011-2012,
## 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.
##
## ===========================
*/

#include "cyfx3device.h"
#include "cyfx3utils.h"
#include "cyfx3gpio.h"
#include "defines.h"
#include "cyfx3i2c.h"

/* Code to read and boot FX3 firmware from I2C EEPROM. */

#define I2C_BUS_TIMEOUT_VALUE (0xFFFFFFFFu)
#define I2C_DMA_TIMEOUT_VALUE (0xFFFFu)
#define I2C_FREQUENCY (400000u)

#define I2C_SLAVE_ADDRESS (0xA0u)

#define I2C_SLAVE_ADDRESS_MAXIM_DES (0xA4u)
#define I2C_SLAVE_ADDRESS_TI_DES (0x60u)
//#define I2C_SLAVE_ADDRESS (0x50)
#define I2C_CMD_WRITE (0)
#define I2C_CMD_READ (1)
#define I2C_START_BYTE2 (0x0004)
#define I2C_RETRY_CNT (2)

#define FW_HEADER_SIZE (4)
#define SECTION_HEADER_SIZE (8)

#define I2C_SLAVE_SPACE (0x10000)
#define GET_BYTE0(addr) ((uint8_t)((addr) & 0xFF))
#define GET_BYTE1(addr) ((uint8_t)(((addr) >> 😎 & 0xFF))

static uint8_t gI2cSlaveAddr = 0;
static uint32_t gI2cByteAddr = 0;
static uint32_t gReadBuf[4]= {0xFF, 0xFF, 0xFF, 0xFF};
static uint8_t gWriteBuf[4] = {1, 2, 3, 4};

/****************************************************************************
* main:
****************************************************************************/

CyBool_t I2c_Write (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootI2cConfig_t i2cConfig;
CyFx3BootI2cPreamble_t preamble;
uint8_t *wd_buf = (uint8_t *)gWriteBuf;

status = CyFx3BootI2cInit ();
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;


i2cConfig.busTimeout = I2C_BUS_TIMEOUT_VALUE;
i2cConfig.dmaTimeout = I2C_DMA_TIMEOUT_VALUE;
i2cConfig.isDma = CyFalse;
i2cConfig.bitRate = I2C_FREQUENCY;
status = CyFx3BootI2cSetConfig (&i2cConfig);
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;

preamble.buffer[0] = I2C_SLAVE_ADDRESS | I2C_CMD_WRITE;
preamble.buffer[1] = 0x10;
preamble.buffer[2] = 0x00;
preamble.length = 3;
preamble.ctrlMask = 0;

status = CyFx3BootI2cTransmitBytes(&preamble, wd_buf, FW_HEADER_SIZE, I2C_RETRY_CNT);
if (status == CY_FX3_BOOT_SUCCESS)
{
return CyTrue;
}

return CyFalse;
}

 

CyBool_t I2c_Read (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootI2cConfig_t i2cConfig;
CyFx3BootI2cPreamble_t preamble;
uint8_t *rd_buf = (uint8_t *)gReadBuf;

status = CyFx3BootI2cInit ();
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;

status = CyU3PI2cInit ();
if (status != CY_FX3_BOOT_SUCCESS)
{
return status;
}

CyU3PMemSet ((uint8_t *)&i2cConfig, 0, sizeof(i2cConfig));

i2cConfig.busTimeout = I2C_BUS_TIMEOUT_VALUE;
i2cConfig.dmaTimeout = I2C_DMA_TIMEOUT_VALUE;
i2cConfig.isDma = CyFalse;
i2cConfig.bitRate = I2C_FREQUENCY;
status = CyFx3BootI2cSetConfig (&i2cConfig);
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;

preamble.buffer[3] = I2C_SLAVE_ADDRESS_MAXIM_DES | I2C_CMD_READ;;
preamble.buffer[0] = I2C_SLAVE_ADDRESS_MAXIM_DES | I2C_CMD_WRITE;;
preamble.length = 4;
preamble.ctrlMask = 0x0004;

// Have to wait for approx. 5 ms to ensure that the slave has completed
// writing the data.
CyFx3BootBusyWait (3500);

status = CyFx3BootI2cSendCommand (&preamble, 16, CyTrue);
if (status != CY_FX3_BOOT_SUCCESS)
{
return status;
}


status = CyFx3BootI2cReceiveBytes (&preamble, rd_buf, FW_HEADER_SIZE, I2C_RETRY_CNT);

if (status == CY_FX3_BOOT_SUCCESS)
{
return CyTrue;
}
else
{
return CyFalse;
}

}

 

int main (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootIoMatrixConfig_t ioCfg;
CyFx3BootGpioSimpleConfig_t gpioConf;
CyBool_t value;

/* HW and SW initialization code */
CyFx3BootDeviceInit (CyTrue);


/* Enable the GPIOs for the LED and the switch. */
ioCfg.isDQ32Bit = CyFalse;
ioCfg.useUart = CyFalse;
ioCfg.useI2C = CyFalse;
ioCfg.useI2S = CyFalse;
ioCfg.useSpi = CyFalse;
ioCfg.gpioSimpleEn[0] = 0;
ioCfg.gpioSimpleEn[1] = (1 << (APP_LED_GPIO1 - 32)) | (1 << (APP_SWITCH_GPIO - 32) | (1 << (APP_LED_GPIO2 - 32)) | (1 << (APP_LED_GPIO3 - 32)) | (1 << (APP_LED_GPIO4 - 32)));

status = CyFx3BootDeviceConfigureIOMatrix (&ioCfg);
if (status != CY_FX3_BOOT_SUCCESS)
{
return status;
}

/* Initialize the GPIO module. */
CyFx3BootGpioInit ();

/* Configure the GPIO for reading the switch input. */
gpioConf.inputEn = CyTrue;
gpioConf.driveLowEn = CyFalse;
gpioConf.driveHighEn = CyFalse;
gpioConf.outValue = CyFalse;
gpioConf.intrMode = CY_FX3_BOOT_GPIO_NO_INTR;

status = CyFx3BootGpioSetSimpleConfig (APP_SWITCH_GPIO, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;

/* Configure the GPIO for driving the LED. */
gpioConf.inputEn = CyFalse;
gpioConf.driveLowEn = CyTrue;
gpioConf.driveHighEn = CyTrue;
gpioConf.outValue = CyFalse;
gpioConf.intrMode = CY_FX3_BOOT_GPIO_NO_INTR;

status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO1, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO2, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO3, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO4, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;

/* We keep looping around and copying the state of the SWITCH GPIO onto the LED GPIO. */
// I2c_Write();

// value = I2c_Write();
// value= I2c_Read();
value= I2c_Read();

if (value == CyTrue)
{
CyFx3BootGpioSetValue(APP_LED_GPIO1, CyTrue); // 0 1 1 0
CyFx3BootGpioSetValue(APP_LED_GPIO2, CyFalse);
CyFx3BootGpioSetValue(APP_LED_GPIO3, CyFalse);
CyFx3BootGpioSetValue(APP_LED_GPIO4, CyTrue);

} else
{
CyFx3BootGpioSetValue(APP_LED_GPIO1, CyFalse); // 1 0 0 1
CyFx3BootGpioSetValue(APP_LED_GPIO2, CyTrue);
CyFx3BootGpioSetValue(APP_LED_GPIO3, CyTrue);
CyFx3BootGpioSetValue(APP_LED_GPIO4, CyFalse);
}

return 0;
}
/*[]*/

 

0 Likes
1 Solution
8 Replies
AliAsgar
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 750 replies posted

Hi

Please find my comments below:

1. What exactly is the Application. Please elaborate so that we can suggest the best approach for implementing it.
2. Why have you used boot library for this implementation. Also, I find that CyFx3BootI2cInit() and CyU3PI2cInit() are used in the function I2c_Read(). We do not recommend to use boot APIs and FW APIs together.
3. preamble.buffer[1] and preamble.buffer[2] are not initialized in I2c_Read() function.
4. What exactly is the failure seen? Is the value not CyTrue when the I2c_Read() returns? Please elaborate the failure so that we can understand it better.

Regards,

AliAsgar

0 Likes
UserP1994
Level 3
Level 3
10 replies posted 10 questions asked 10 sign-ins

I want to read data from I2C_SLAVE_ADDRESS_MAXIM_DES this adress I also tried this example but it is not working.

 

/*
## Cypress FX3 Boot Firmware Example Source file (main.c)
## ===========================
##
## Copyright Cypress Semiconductor Corporation, 2011-2012,
## 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.
##
## ===========================
*/

#include "cyfx3device.h"
#include "cyfx3utils.h"
#include "cyfx3gpio.h"
#include "defines.h"
#include "cyfx3i2c.h"

/* Code to read and boot FX3 firmware from I2C EEPROM. */

#define I2C_BUS_TIMEOUT_VALUE (0xFFFFFFFFu)
#define I2C_DMA_TIMEOUT_VALUE (0xFFFFu)
#define I2C_FREQUENCY (400000u)

#define I2C_SLAVE_ADDRESS (0xA0u)
//#define I2C_SLAVE_ADDRESS_MAX (0xA4u)
#define I2C_CMD_WRITE (0)
#define I2C_CMD_READ (1)
#define I2C_START_BYTE2 (0x0004)
#define I2C_RETRY_CNT (2)

#define FW_HEADER_SIZE (4)
#define SECTION_HEADER_SIZE (8)

#define I2C_SLAVE_SPACE (0x10000)
#define GET_BYTE0(addr) ((uint8_t)((addr) & 0xFF))
#define GET_BYTE1(addr) ((uint8_t)(((addr) >> 😎 & 0xFF))

static uint8_t gI2cSlaveAddr = 0;
static uint32_t gI2cByteAddr = 0;
static uint32_t gReadBuf[4]= {0xFF, 0xFF, 0xFF, 0xFF};
static uint8_t gWriteBuf[4] = {1, 2, 3, 4};

/****************************************************************************
* main:
****************************************************************************/

CyBool_t I2c_Write (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootI2cConfig_t i2cConfig;
CyFx3BootI2cPreamble_t preamble;
uint8_t *wd_buf = (uint8_t *)gWriteBuf;

status = CyFx3BootI2cInit ();
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;


i2cConfig.busTimeout = I2C_BUS_TIMEOUT_VALUE;
i2cConfig.dmaTimeout = I2C_DMA_TIMEOUT_VALUE;
i2cConfig.isDma = CyFalse;
i2cConfig.bitRate = I2C_FREQUENCY;
status = CyFx3BootI2cSetConfig (&i2cConfig);
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;

preamble.buffer[0] = I2C_SLAVE_ADDRESS _MAX| I2C_CMD_WRITE;
preamble.buffer[1] = 0x10;
preamble.buffer[2] = 0x00;
preamble.length = 3;
preamble.ctrlMask = 0;

status = CyFx3BootI2cTransmitBytes(&preamble, wd_buf, FW_HEADER_SIZE, I2C_RETRY_CNT);
if (status == CY_FX3_BOOT_SUCCESS)
{
return CyTrue;
}

return CyFalse;
}

 

CyBool_t I2c_Read (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootI2cConfig_t i2cConfig;
CyFx3BootI2cPreamble_t preamble;
uint8_t *rd_buf = (uint8_t *)gReadBuf;

status = CyFx3BootI2cInit ();
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;


i2cConfig.busTimeout = I2C_BUS_TIMEOUT_VALUE;
i2cConfig.dmaTimeout = I2C_DMA_TIMEOUT_VALUE;
i2cConfig.isDma = CyFalse;
i2cConfig.bitRate = I2C_FREQUENCY;
status = CyFx3BootI2cSetConfig (&i2cConfig);
if (status != CY_FX3_BOOT_SUCCESS)
return CyFalse;

preamble.buffer[0] = I2C_SLAVE_ADDRESS_MAX | I2C_CMD_WRITE;
preamble.buffer[1] = 0x10;
preamble.buffer[2] = 0x00;
preamble.buffer[3] = I2C_SLAVE_ADDRESS_MAX | I2C_CMD_READ;
preamble.length = 4;
preamble.ctrlMask = I2C_START_BYTE2;

status = CyFx3BootI2cReceiveBytes (&preamble, rd_buf, FW_HEADER_SIZE, I2C_RETRY_CNT);
if (status == CY_FX3_BOOT_SUCCESS)
{
if ((rd_buf[0] == 1) && (rd_buf[1] == 2) && (rd_buf[2] == 3))
{
return CyTrue;
}
}

return CyFalse;
}

 

int main (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootIoMatrixConfig_t ioCfg;
CyFx3BootGpioSimpleConfig_t gpioConf;
CyBool_t value;

/* HW and SW initialization code */
CyFx3BootDeviceInit (CyTrue);


/* Enable the GPIOs for the LED and the switch. */
ioCfg.isDQ32Bit = CyFalse;
ioCfg.useUart = CyFalse;
ioCfg.useI2C = CyFalse;
ioCfg.useI2S = CyFalse;
ioCfg.useSpi = CyFalse;
ioCfg.gpioSimpleEn[0] = 0;
ioCfg.gpioSimpleEn[1] = (1 << (APP_LED_GPIO1 - 32)) | (1 << (APP_SWITCH_GPIO - 32) | (1 << (APP_LED_GPIO2 - 32)) | (1 << (APP_LED_GPIO3 - 32)) | (1 << (APP_LED_GPIO4 - 32)));

status = CyFx3BootDeviceConfigureIOMatrix (&ioCfg);
if (status != CY_FX3_BOOT_SUCCESS)
{
return status;
}

/* Initialize the GPIO module. */
CyFx3BootGpioInit ();

/* Configure the GPIO for reading the switch input. */
gpioConf.inputEn = CyTrue;
gpioConf.driveLowEn = CyFalse;
gpioConf.driveHighEn = CyFalse;
gpioConf.outValue = CyFalse;
gpioConf.intrMode = CY_FX3_BOOT_GPIO_NO_INTR;

status = CyFx3BootGpioSetSimpleConfig (APP_SWITCH_GPIO, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;

/* Configure the GPIO for driving the LED. */
gpioConf.inputEn = CyFalse;
gpioConf.driveLowEn = CyTrue;
gpioConf.driveHighEn = CyTrue;
gpioConf.outValue = CyFalse;
gpioConf.intrMode = CY_FX3_BOOT_GPIO_NO_INTR;

status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO1, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO2, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO3, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;


status = CyFx3BootGpioSetSimpleConfig (APP_LED_GPIO4, &gpioConf);
if (status != CY_FX3_BOOT_SUCCESS)
return status;

/* We keep looping around and copying the state of the SWITCH GPIO onto the LED GPIO. */
// I2c_Write();

// value = I2c_Write();
// value= I2c_Read();
value= I2c_Read();

if (value == CyTrue)
{
CyFx3BootGpioSetValue(APP_LED_GPIO1, CyTrue); // 0 1 1 0
CyFx3BootGpioSetValue(APP_LED_GPIO2, CyFalse);
CyFx3BootGpioSetValue(APP_LED_GPIO3, CyFalse);
CyFx3BootGpioSetValue(APP_LED_GPIO4, CyTrue);

} else
{
CyFx3BootGpioSetValue(APP_LED_GPIO1, CyFalse); // 1 0 0 1
CyFx3BootGpioSetValue(APP_LED_GPIO2, CyTrue);
CyFx3BootGpioSetValue(APP_LED_GPIO3, CyTrue);
CyFx3BootGpioSetValue(APP_LED_GPIO4, CyFalse);
}

return 0;
}
/*[]*/

CD-American
dynamit -Switchis

Thank you

0 Likes

Hello,

Could you please let us know answers to the below questions to understand the problem better

1. Where exactly is the failure seen? Is the value not CyTrue when the I2c_Read() returns? Please elaborate the failure so that we can understand it better

2. Is the write to  I2C_SLAVE_ADDRESS _MAX successful?

3. Could you please check if any API ins I2c_Read fails? If yes, please let us know the error code

Regards,
Rashi
0 Likes
Hi, I found out that XRST is low, and I have to set it in, but I don't know how, can you help me with an idea? thank you

 

0 Likes

Hello,

Please let me know which FX3 firmware are you using as the base of your firmware.

Is it the firmware with AN75779?

Regards,
Rashi
0 Likes
UserP1994
Level 3
Level 3
10 replies posted 10 questions asked 10 sign-ins

Hello,

On my pcb I have DS90UB960-Q1 deserializer and CYUSB306X, and I want to read a DS90UB960 register, and for that I need to set the XRST pin to high, can anyone give me an idea? thank you

0 Likes

Hello,

From XRST, I understand that it is a Reset IO. Is my understanding correct,? 

If yes, please refer to CyU3PMipicsiSetSensorControl API. 

This function is used to drive the XRES and XSHUTDOWN signals from the CX3 to Image sensor. The function allows for the signals to be driven high or low. The function can drive either one of the two signals or both signals (both driven high or both driven low) simultaneously. To set both signals to the same value use the mask (CY_U3P_CSI_IO_XRES | CY_U3P_CSI_IO_XSHUTDOWN) as value for io.
To set the two signals to separate values multiple calls to this function are required (once for each signal).

For example  CyU3PMipicsiSetSensorControl (CY_U3P_CSI_IO_XRES, CyTrue);

Regards,
Rashi
0 Likes
0 Likes