Abnormal behavior while reading VCNL4200 proximity sensor

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Abnormal behavior while reading VCNL4200 proximity sensor

2,664 Views
_Ferrari_
Contributor V

Dear all,

I connected the LPC55S28-EVK to the proximity sensor VCNL4200. The LPC55S28-EVK is configured as master and VCNL4200, of course, as slave.

I developed a simple software to read the DeviceID of the sensor: in an endless while I inserted the reading of the DeviceID  of the sensor

 

 int i =0;
 while(1) {
        i++ ;
        /* 'Dummy' NOP to allow source level single stepping of
            tight while() loop */
        __asm volatile ("nop");
        int res= readID();
        PRINTF("%3d %x\n",i,res);
    }

 

 the readID funcrion is:

#define EXAMPLE_I2C_MASTER FLEXCOMM4_PERIPHERAL
#define I2C_MASTER_SLAVE_ADDR_7BIT VCNL4200_I2CADDR
#define I2C_DATA_LENGTH 2
uint8_t g_master_txBuff[I2C_DATA_LENGTH];
uint8_t g_master_rxBuff[I2C_DATA_LENGTH];

int readID() {
	int ID;
    //if (readData(VCNL4200_DeviceID_REG) != 0x1058)
    ID=readData(VCNL4200_DeviceID_REG);
	return ID;
}

uint16_t readData(uint8_t command_code) {
	uint8_t deviceAddress;
	deviceAddress=command_code;
	status_t reVal        = kStatus_Fail;
  if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
    {
        reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, &deviceAddress, 1, kI2C_TransferNoStopFlag);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

        reVal = I2C_MasterRepeatedStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Read);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

        reVal =I2C_MasterReadBlocking(EXAMPLE_I2C_MASTER, g_master_rxBuff, I2C_DATA_LENGTH, kI2C_TransferDefaultFlag);
        if (reVal != kStatus_Success)
        {
            return -1;
        }

        reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
        if (reVal != kStatus_Success)
        {
            return -1;
        }
    }
	return g_master_rxBuff[1]<<8 | g_master_rxBuff[0];
}

I used MCUXpresso IDE v11.5.1 [Build 7266] [2022-04-13] and the routine  readData is developed according the i2c_polling_b2b_master.c example.

According the datasheet of VCNL4200 VCNL4200_I2CADDR is 0x51 and VCNL4200_DeviceID_REG id 0x0E.

I connected the proximity sensor to the demo board as following:

I2C_SCL P17-1 I2C_SCL P17-1
I2C_SDA P17-3 I2C_SDA P17-3
GND P17-7 GND P17-7

and I used P16-8 (3.3V) as power supply of the proximity sensor.

I compiled the software and I debugged it but the data displayed on the console is:

Hello World
1 ffff
2 1058
3 ffff

 

only three readings are made and only the second one is correct.

After the third reading the program hangs-up in the routine I2C_PendingStatusWait.

Did you have a similar problem ?

How did you fix it ?

Thank you very much for your help and cooperation.

Best regards.

 

 

0 Kudos
Reply
7 Replies

2,641 Views
_Ferrari_
Contributor V

Dear Pavel,

thank you for your replly.

You wrote:

> Is this issue occurring in the [i2c_polling_b2b_master] example too?

Yes, I have the same issue

Thank you very much for your help and cooperation

regards

 

 

0 Kudos
Reply

2,637 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

I review the code on my side and it works as expected, could you review your code, or in another case could you update the SDK and the IDE?

Best regards,
Pavel

0 Kudos
Reply

2,646 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

Is this issue occurring in the [i2c_polling_b2b_master] example too?

Best regards,
Pavel

0 Kudos
Reply

2,600 Views
_Ferrari_
Contributor V

Yes, I have the same issue

Thank you very much for your help and cooperation

regards

0 Kudos
Reply

2,576 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

I apologize for the late response, I will share with you an example that works in the LPC55s28 EVK, you can test and if this does not work maybe you have something missing in your hardware. If this does not work, Could you share the image from the logic analyzer to review the frame?

Best regards,
Pavel

0 Kudos
Reply

2,512 Views
_Ferrari_
Contributor V

Dear all,

I downloaded the project that handles the on board accellerometer and it worls.

Unfortunately the I2C periheral can't be configured by the MCUXpresso periherals configurator.

 

 

regards

0 Kudos
Reply

2,509 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

What do you need to modify in the configuration of the I2C? The image below is from the config tool.

Pavel_Hernandez_0-1663168967091.png

Best regards,
Pavel

 

0 Kudos
Reply