interfacing temperature sensor using I2c

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

cross mob
CSK10
Level 3
Level 3
First like received First like given 50 sign-ins

Hello ,

I have a peice of code written for interfacing a  I2c based temperature sensor with Fx2lp. If i write this code in TD_POLL function the device does not re-enumerate.
Can someone explain me this reason and also then what would be the appropriate approach  here ?

 

Thanks  

0 Likes
1 Solution
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

TD_Poll is an infinite loop while TD_Init() is for initialising endpoints, clock and LEDs. Can you please check Vend_Ax example code?

You can use a separate .c file for i2c related functionality and not include it with TD_Init and TD_Poll.

Regards,

Mallika

 

View solution in original post

0 Likes
3 Replies
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

Could you please provide more details about your application like what sensor are you using and schematics if possible.

How does the device enumerate after reprogramming?

Regards,

Mallika

0 Likes

Hi I am using temperature sensor 102  for interfacing . I also stumbled upon this article Why Certain EZ-USB® FX2LP™ DVK Firmware Examples F... - Infineon Developer Community  but still doesnt help me much.

 

EZUSB_InitI2C(); // Initialize I2C bus
BUFFER[0] = Reg_temp;
EZUSB_WriteI2C(Tmp102_ADDR, 1, BUFFER);
EZUSB_WaitForEEPROMWrite(Tmp102_ADDR); // wait for I2C write to complete

EZUSB_ReadI2C(Tmp102_ADDR, 2, BUFFER);
//Combine the bytes
val = ((WORD)BUFFER[0] << 4) | (BUFFER[1] >> 4);
// Convert to 2's complement, since temperature can be negative
if ( val > 0x7FF )
{
val |= 0xF000;
}
// Convert to float temperature value (Celsius)
temp_c = val * 0.0625;
// Convert temperature to decimal format
temp_c *= 100;
sprintf((char*)BUFFER,
"%u.%02u C\r\n",
((unsigned int)temp_c / 100),
((unsigned int)temp_c % 100));

 

this is the code that i write in the TD_POLL function 

0 Likes
MallikaK_22
Moderator
Moderator
Moderator
50 likes received 750 replies posted 250 solutions authored

Hi,

TD_Poll is an infinite loop while TD_Init() is for initialising endpoints, clock and LEDs. Can you please check Vend_Ax example code?

You can use a separate .c file for i2c related functionality and not include it with TD_Init and TD_Poll.

Regards,

Mallika

 

0 Likes