I2C "SearchDevices on bus"

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

tuxscreen
Posts: 14
Joined: Wed May 02, 2012 4:53 pm

I2C "SearchDevices on bus"

Postby tuxscreen » Wed Aug 19, 2015 5:14 pm

Hi,

I have implemented some PreCheck function, where I check the availability of several chips on the bus. It serves mostly debug and programmers demands.

Code: Select all

   snip

data = 0;
for (i2c_addr = 1; i2c_addr < 0x7e; i2c_addr++)
 {
         res = I2CH_MasterTransmitTimeout(drvp, i2c_addr, &data, 1, NULL, 0, MS2ST(5));       
         if (res == RDY_OK)
            my_printf("%s: Device     at %02x\n", __func__, i2c_addr);
        else
            my_printf("%s: Device NOT at %02x\n", __func__, i2c_addr);
}


The code works perfectly for several devices I had in the past.

Now I have some new Chip, a charger controller. This chip has not all registers as writeable, only very selected regs are readable, some are writable.

If I run the quoted code on this chip, Chibi does not see it, because first it transfers the i2c-address (this is ack'd as I see on the oszi) and afterwards the register is written but this sub-Transaction is not ack'd by the charger-controller.
After all the function fails.

How can I get Chibi to only set the address, and return the result to me?
I also tried to set tx_bytes to 0, does not work?

BR
Marc

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: I2C "SearchDevices on bus"

Postby Giovanni » Wed Aug 19, 2015 6:19 pm

Hi,

Have you tired the i2CMasterReceive() function? I am not sure it would work because just sending the address is something I never seen.

Giovanni

tuxscreen
Posts: 14
Joined: Wed May 02, 2012 4:53 pm

Re: I2C "SearchDevices on bus"

Postby tuxscreen » Thu Aug 20, 2015 8:25 am

Hi Giovanni,

yes, I tried the Receive function, too. Out of my perspective, it just hangs, if you set rx_bytes to 0.

You are completely right. The only case where you Need this, is if you check the Hardware on the bus.

It's like:
see http://www.lm-sensors.org/wiki/man/i2cdetect or here: http://www.lm-sensors.org/browser/i2c-t ... 2cdetect.c

I have a test setup where I have connected a raspberry pi and a STM32 w/ Chibi to the same sensor board. If there are problems I also check if the Problem is still there if only one master is connected.

With the RaspberryPi I see all three devices on my board, with Chibi I see only one.

There are several Solutions
one is to have an API (just like in CMSIS), where you can do such stuff without DMA
second would be to have just such a Routine like i2cdetect
third would to pimp the i2c irq to handle such a mode, e.g. an I2C_ADDR_ONLY flag or a handling for rx_bytes && tx_bytes are 0.

What do you think?

BR
Marc

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: I2C "SearchDevices on bus"

Postby Giovanni » Thu Aug 20, 2015 8:39 am

You may propose a patch. Putting counters to zero looks like the less disruptive.

Giovanni

crispus
Posts: 24
Joined: Sat Aug 27, 2016 10:14 am
Has thanked: 4 times
Been thanked: 3 times

Re: I2C "SearchDevices on bus"

Postby crispus » Sat Dec 07, 2019 3:19 pm

I know this thread is old, but I kinda got around it by restarting the i2c driver:

Code: Select all

       i2cStop(cpuI2C);
       i2cStart(cpuI2C, &cpuI2cCfg);
       msg_t ret = i2cMasterTransmitTimeout(cpuI2C, addr, tx_buffer, 1,
                rx_buffer, 0, TIME_MS2I(10));


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 21 guests