Possible bug in I2C driver shifting adress.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
7znakow
Posts: 7
Joined: Sun Jul 14, 2013 5:25 pm

Possible bug in I2C driver shifting adress.

Post by 7znakow »

After some battle with stm32f4discovery board and built-in DAC(CS43l22) I disovered why I couldn't receive ACK signal. The problem was that everytime when I tried to make a transfer, address of device was shifted by 1 to the left (addr << 1) that's why DAC 0x94 addres became 0x128. I have discovered that by checking every adress from 0 to 255 and I found that transfer address was 0xA4 (0x94 >> 1). The solution to this problem was changing

Code: Select all

i2cp->addr = (addr << 1);
to

Code: Select all

i2cp->addr = (addr << 0);

in i2c_lld_master_transmit_timeout and i2c_lld_master_receive_timeout in lld drivers (i2c_lld.c) in I2Cv1 folder.

Can someone can tell me why address had to be shifted?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Possible bug in I2C driver shifting adress.

Post by Giovanni »

Hi,

The address is a 7 bits field, the LSb is used as RW flag, what you pass to the API is the value of the address field not the whole first byte.

This is done in order to be compatible with 10 bits addressing and because passing the R/W flag makes no sense (it is handled internally).

Giovanni
7znakow
Posts: 7
Joined: Sun Jul 14, 2013 5:25 pm

Re: Possible bug in I2C driver shifting adress.

Post by 7znakow »

Oh, yes compatibility, now that make sense. I've been looking only from 7 bit adress perspective.
Post Reply