Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4867

SDK • Re: i2c slave mode question [ANSWERED]

$
0
0
Maybe some of these: https://www.renesas.com/us/en/document/ ... ?r=1563671

They are many times programmable. I expect you could use a Pico to do it. I haven't tried but hope to find time soon.

They contain an I2C macrocell with programmable address, though I don't believe the I2C macrocell can be made to NACK.

However, I expect the "circuits" that you can configure are sophisticated enough to make a mock I2C decoder that identifies that it has been addressed and NACKs. https://www.renesas.com/us/en/document/ ... spi-bridge
Sending the NACK isn't strictly required in my use case. For me it's more about mock hardware and learning how the communications work between the Pi and the Pico/RP2040 and then taking that knowledge to make something with it. So if I can see how NACK would work with only one device address that's good enough the idea of multiple addresses more for what I have planed to maintain backwards compatibility but use a different address for my own implementation. Another reason for the multiple addresses is I do a bus scan to detect what addresses are in use and depending on what addresses are detected I can know what configuration to use.

I also want to see what probing the bus does to the device. I read that it can mess up some chips so I want write my device to avoid that.

In an effort to maintain backwards compatibility and use a different address I could infer from everything (examples, datasheet, SDK documents) I read that it would be possible to switch addresses (on the fly) while using the SDK? So if my device I want to mimic were to use address 0x55 I could simply mock all it's registers and since it has unused ones I could use one of them to basically switch the alternate mode those changing the device address to 0x56 for example? This way under normal operations it would act just the same as it would without my changes and then switch the value in the register and it becomes a different device. I would only need to redirect the callback?

From the example this would set up the default device

Code:

    // configure I2C0 for slave mode    i2c_slave_init(i2c0, I2C_SLAVE_ADDRESS, &i2c_slave_handler);
Then in i2c_slave_handler when a magic value is written to the right address I could set a flag that would run this code

Code:

    // configure I2C0 for slave mode using second device    i2c_slave_init(i2c0, I2C_SLAVE_ADDRESS2, &i2c_slave_handler2);
Or should you reset the bus with the i2c_slave_deinit first. The software on the Pi would need to allow time for this to complete.

Statistics: Posted by DarkElvenAngel — Thu Feb 29, 2024 6:58 pm



Viewing all articles
Browse latest Browse all 4867

Trending Articles