I2c to spi bridge

Hi, I have more atmega328p as slave in I2C protocol connected to Arduino as master. Now I need use more sensors via I2C connected to my atmega328p, but I2C is occupied.

Idea:
Is possible create I2C bridge to for example SPI?
For example via some ATtiny (ATtiny20/40 haas one SPI and one I2C)
or some existing chip?

I need something small, not module, not expensive, onthe pcb.

But I am only beginer, and I dont know how to solve it. Cansomebody help me?

What do you mean by this ?
I2C is a bus protocol so you can connect multiple devices to it

2 Likes

What do you mean, "occupied"? I²C is a bus, designed to have many sensors attached.

@ UKHeliBob, @ PaulRB
atmega328p now comunicate as slave with Arduino as master, I not have free I2C, so can not connect I2C sensors to atmega328p.
I need alternative solution:
get data from sensor via I2C to chip, or MCU, and send to atmega328p via SPI.

Just trying to clarify your setup: you want a 328P to be an I2C master to several I2C sensors. At the same time you also want the 328P to be an I2C slave device to another Arduino (which one?).

Can't the Arduino do all the work and avoid the separate 328P?

If everything stays on the same pcb board (without long wires to sensors), then there is no problem to connect about 20 devices to the I2C bus. Take care of the voltage level and (internal) pullup resistors and keep SDA away from SCL and about 30 devices should be possible. If you keep the pcb board small and stack the I2C devices, then even more is possible.

In theory, the I2C bus can deal with almost 127 devices.

Yes,
328P is slave for Arduino, and also master for sensors,
I have in 328P more logic, and I have more 328P,
And no, Arduino can not do it, it is only master and ask data from slave (328P)

I have 25 of 328P (slaves), there are some logic for buttons,..., and now I need add sensors there
And I have one arduino as master, and Arduino switch between 328P (slaves), and ask data.

So I need connect sensors for each 328P (slaves), and IC is used for comunication with master.

Do you have a schematic or can you make a drawing on a piece of paper and make a photo of it ?
I assume that there is not a real hardware multiplexer to switch between the Slaves ?

Each Slave could use a software I2C library to talk to sensors. You might have to change the source of the library for that sensor.
Each Slave can also use SPI, but there is no standard "bridge" software to connect the SPI bus to the I2C bus, you have to do that yourself for every sensor.

Adafruit has BusIO library to be able to use a single interface for many different sensors (SPI and I2C). It might be of interest for you.

One master arduino ask for data slaves every time

in each slave is some logic, for buttons .... and more

now I need connect I2C sensors to slaves, I can not do it, because, slaves communicate with master arduino via I2C

Idea:
create bridge from I2C to SPI

Thx, I will try it

Writing a driver for the hardware spi-to-i2c chip and changing every library for the sensors or using a (almost) drop-in replacement for the I2C libraries when using a software I2C library.
I know what I would do.

Either way, you have to do some work for each and every sensor.
I don't remember anyone doing this on such a scale, so I don't know a working example.

This topic looks familiar from another forum. :slight_smile: Final advice was SC18IS600 like @markd833 wrote.
However, the price for this chip is a bit high. It's close to price for ATmega328P so you an use some cheap ATtiny with SPI and I2C (TWI) as a bridge. This require some effort on SW level, but it will pay off in this amount.
Another solution, which I found just out of curiosity, could be use of LTC4317 - Dual I2C/SMBus Address Translator. The price for this chip seems to be more reasonable.

EDIT: ATmega328PB has 2xI2C bus.

Here is a Arduino Mega with 30 I2C buses: https://wokwi.com/arduino/projects/307886580731740737?dark=1

A software I2C bus is not worse than a hardware I2C bus. It takes about the same amount of time on a Arduino Uno.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.