XMC 2Go - I2C - RGB Sensor

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

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Hello ladies and gentlemen,

I am a new member of the Infineon Forum and I hope that you guys are able to support me with your knowledge.
I have been looking for several days to find some supporting DAVE examples that help me to read in the sensor data of my RGB sensor, but at the end I was not able to manage the communication.

As I already mentioned I use a RGB sensor (Vishay VEML6040), which has an I2C interface. I want to read in the data with my XMC 2Go.
I got some support from Vishay. They provided me an C-Code for this sensor, but still I am not able to set up the communication.
Maybe I have too less experience with that, but I really need to do this for my studies.
Attached you will find the supporting code from Vishay, the protocol format and the DAVE code of my attempt.

I've used one I2C001 App and two NVIC002 as Receive Interrupt and Protocol Interrupt (I got this information out of an example).
SDA should be on Port 0.15 and SCL on Port 2.0.

The datasheet of the sensor shows some information about the sensor and the protocol: http://www.vishay.com/docs/84276/veml6040.pdf

Apart from my I2C communication problem I would like to know if there is an easy way to read out the sensor data directly via the USB connection like in the provided XMC 2G InitialStart Program with HTerm?

It would help me a lot to get some feedback or suggestions, I think some of you know how to do this in a few minutes...

Thank you very much for your effort, I really appreciate this!!

Kind regards,
schmidi
0 Likes
5 Replies
chismo
Employee
Employee
First like received
Hello Schimidi,

The I2C protocol requires external pull-up resistors on the SDA and SCL bus lines.
The recommendations are 10kohm for standard mode and 2kohm for fast mode.
Are these already in place?

And are you able to observe either through a scope or the debugger view, where did the communications fail?
For example, there is no acknowledgement from the slave with the first address byte?

Regards,
Min Wei
0 Likes
Not applicable
Hi Min Wei,

thank you very much for your reply!
Since I am using the Vishay Eval-Board, I thougth that the pull-up resistors where already in place...
But I had a look on the schematics, which I got recently and they are only included if I use the USB dongle... So, I missed that point, thank you very much for this hint!
I am away 14 days from now... I will try it again when I am back.

I was debugging through the program, but after the Acknowledge, of the Master, (I think it was the 2 one) the program wasn't able to get one step further to finish of the communication.
Do you think that my code looks fine? Since I never applied a I2C communication...

I will tell you my status when I am back from my holidays.

Kind Regards,
schmidi
0 Likes
Not applicable
Hi Min Wei,

I just fixed the issue with the pull-up resistors, I have placed two 2.2 kOhm resistors (recommendation of Vishay) on the SDA and SCL bus line.
Now the further problem is that I do not know, how I am able to identify errors. Should I use the debugger view and go through the program step by step?
And in case that everything is correct how can I display the RGB values which I get from the sensor?

Thank you again for your effort!

Kind Regards,
schmidi
0 Likes
chismo
Employee
Employee
First like received
Hello Schimidi,

Yes, the debug mode is meant to help trouble-shoot any potential issues.

From you code, I think there are two aspects that needs to be investigated further.

1) In your write function which consists of 5 calls of the I2C001_WriteData() API, the 4th one is missing a semi-colon.

data1.Data1.TDF_Type = I2C_TDF_MTxData;
data1.Data1.Data = *I_O_msb;
while (!I2C001_WriteData(&I2C001_Handle0, &data1))


2) I think the read function will result in an endless loop due to the while(i2cbusy) statement. i2cbusy is defined to be always 1?
Also, I would suggest to use the TDF code "I2C_TDF_MRxAck0" for the first data to be received.
This code means receive data and send acknowledgement.
TDF code "I2C_TDF_MRxAck1", which means receive data and send not-acknowledgement, should be used only for the last data to be received prior to the stop condition.

Regards,
Min Wei
0 Likes
Not applicable
Hi Min Wei,

Thank you very much for your response I've solved the problem!
As you said the first acknowledgement in the read command must be "I2C_TDF_MRxAck0".
Further, the device address (0x10) must be shifted by 1 bit to the left, because it is a 7-bit address, so it became 0x20 -> the additional zero is used as indicator for a write command.
The communication worked after these changes.

Kind regards,
schmidi
0 Likes