I2C communication with TLE493D-2AB6 2D hall sensor

Announcements

Measure CO2 When It Matters - Infineon’s XENSIV™ PAS CO2 now comes in SparkFun Red. Check it now!

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.
Michael_K
Level 3
Level 3
25 replies posted 10 likes given 50 sign-ins

Hello everybody,

I have some problems to communicate with a 2D hall sensor from Infineon via I2C.

First some background information:

CY8CKIT-42 PSoC 4 Pioneer Kit

PSoC Creator 4.4

TLE493D-A2B6 (https://www.infineon.com/dgdl/Infineon-TLE493D-W2B6-UM-v01_01-UserManual-v01_11-EN.pdf?fileId=5546d4...

I wrote myself two functions which allow me to read or write a register.

The TLE493D has a 2-byte read command and a 1-byte read command. So I try to write the register first and change it to 1-byte read command mode.

When I try to write a register, it works, but when I try to read a register, I always get a NACK after I send the register address of the sensor. I don't know what the problem is.

 

I tried the read function with a MPU6050 sensor and it worked. I could read the register.

Why can't I read the registers properly?

I have added some pics and the project in the attachment.

 

Best Regards and Thank You

Michael

0 Likes
1 Solution
jepaz
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hi,

I think you just need to change your read routine so that it uses the I2C_1_I2C_MODE_COMPLETE_XFER  flag, they are two separate processes that have to be completed acknowledged  separately,

when using this flag I2C_1_I2C_MODE_NO_STOP you would not use the API Write/Read Buffer but work with Bytes instead

 

uint8 tle493d_ReadReg(uint8 Reg)
{
uint8 Write_Buf[1] = {0};
Write_Buf[0] = Reg;

uint8 Read_Buf[1] = {0};

I2C_1_I2CMasterWriteBuf(TLE493_ADDRESS,(uint8 *)Write_Buf,1,I2C_1_I2C_MODE_COMPLETE_XFER  );
while((I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_WR_CMPLT)== 0){}

I2C_1_I2CMasterReadBuf(TLE493_ADDRESS, (uint8 *)Read_Buf,1,I2C_1_I2C_MODE_COMPLETE_XFER  );
while((I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT) == 0){}

return Read_Buf[0];
}

 

hope it helps

 

View solution in original post

2 Replies
jepaz
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hi,

I think you just need to change your read routine so that it uses the I2C_1_I2C_MODE_COMPLETE_XFER  flag, they are two separate processes that have to be completed acknowledged  separately,

when using this flag I2C_1_I2C_MODE_NO_STOP you would not use the API Write/Read Buffer but work with Bytes instead

 

uint8 tle493d_ReadReg(uint8 Reg)
{
uint8 Write_Buf[1] = {0};
Write_Buf[0] = Reg;

uint8 Read_Buf[1] = {0};

I2C_1_I2CMasterWriteBuf(TLE493_ADDRESS,(uint8 *)Write_Buf,1,I2C_1_I2C_MODE_COMPLETE_XFER  );
while((I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_WR_CMPLT)== 0){}

I2C_1_I2CMasterReadBuf(TLE493_ADDRESS, (uint8 *)Read_Buf,1,I2C_1_I2C_MODE_COMPLETE_XFER  );
while((I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT) == 0){}

return Read_Buf[0];
}

 

hope it helps

 

Michael_K
Level 3
Level 3
25 replies posted 10 likes given 50 sign-ins

Hello jepaz, thx for the advice. I wanted to reply yesterday, but the forum was locked.  I've tried it out, but it was the same.  I have found another error and I have set the wrong bits in the register, because in the example I am follwing the values were in DEC and I have written them in HEX.  So maybe it don't work, because I haven't change the config and mode register.

 

But I've written a new function. The function reads all 23 registers and stores the content in an array. I have stored only the relvant ones for me in variables. I doesn't run perfectly, but at least I get the values. (https://github.com/Infineon/TLE493D-3DMagnetic-Sensor/issues/13)

 

uint8* tle493d_read()
{
    static uint8 Read_Buf[23] = {0};
    I2C_1_I2CMasterReadBuf(TLE493_ADDRESS,(uint8 *)Read_Buf,23,I2C_1_I2C_MODE_REPEAT_START);
    while((I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT) == 0){}
    
    return Read_Buf;
}

 

 

I wanted add a UART interface, but somehow I mess up the source code or the project. Now I get no values and I have to clean up my code.

The sensor seems to be okay, because with an arduino nano I get plaubisble values.

 

I will be in touch if I get stuck and need some help

 

Best Regards

Michael