2 channels I2C for Atmega328 - serial-port

I have an Atmega328 which has to be a slave of an I2c network (because this Atmega is one of the sensors of a bigger network and it's the only available bus), and read+process data from an ADC ADS1100 on request from an I2C master.
I would like to reduce the workload of the master outside of this system: it can't be the mediator of 2 slaves communicating with each other so I have a problem here and I need split the I2C in two so that the atmega can be master of a channel and slave of the other.
Is the library SoftwareSerial compatible with the I2C interface of the ADS1100 so that I can use the proper one with the master and any GPIO for a separate channel toward the ADC? Or do I have to multiplex the proper I2C for listen-acquire-transmit operation? Is there another option?
Thanks in advance.

Related

Advice needed for connecting multiple arduinos as slave to raspberry pi

I have a project in hand where I need to connect 5 or more arduinos as slaves to Raspberry Pi. Load Cells, Reed Switch, Solenoid lock will be connected to each of the arduino. The arduinos need to send the weight readings when a communication is started by the raspberry pi(master). Only a single arduino will be activated at a time. The arduinos will be placed at a maximum of 6ft distance from the raspberry pi. I need advice regarding how to make this connection. I read that I2C cannot be used for long distances so I am unsure if 6 ft is a long distance for I2C. Next, I am trying to see if a USB would work for my case but the issue is the Pi has only 4 USB slots. So can I use a external USB hub with an external power supply and connected each of the arduinos to the USB hub and provide individual power supply to the arduinos? Will this arrangement work or should I be looking at any other protocol apart from I2C and USB?? Any advice on this will be much appreciated. Thanks a lot for your time.
Arduino (Nano, Uno, Mega etc.) can communicate via SPI, I2C or UART.
Long story short, SPI is not suitable for your application. It is used for fast data transfer over short distances (usually milimeters or centimeters), so mainly for communication between chips mounted on the same PCB or PCBs close together (e.g. display shields).
Using I2C is perfectly fine (let's say up to 10 meters) and in your case it is a way to go. The maximum possible length depends on baud rate, for 10 meters a 9600 baud rate would be OK. The big advantage is that you need only 2 wires to connect all Arduinos, the disadvantage is that only one device can transfer data at the time – in your case, that does not matter.
UART is used for communication with many external modules (GSM, GPS, HMI, ...) and also in combination with USB-TTL chip for communication via USB (virtual COM port). In your case, you can use UART e.g. in combination with external UART-RS485 converter module, but there is no need since you can use I2C.

I2C on ESP32 or Arduino: what's the max number of slaves using the BMP388 sensor

BMP388: what is the maximum of slave addresses in I2C mode
In I2C mode with one master how many BMP388 as slave can be connect to an Arduino UNO?
From the datasheet I understand that there are only 2 adresses possible in I2C mode (0x76 or 0x77) as designated by bit 7 in the device address and configured via the SDO (pin 5) port to ground or plus.
In SPI mode, as I hope to understand well from the datasheet, it's up to 128 BMP388 addresses.
My questions are:
-Am I understanding well that in I2C mode the maximum number of slaves is two?
-Of course I can connect a lot of BMP388's in series to the Arduino, but how can I address them in I2C mode. Or should I use SPI mode?
-Is there any documentation, except the datasheet, that makes this more clear?
-Is there any example Arduino code for the I2C situation?
You understood the i2c addressing correctly. There can only be 2 addresses for
BMP388 controlled by SDO pin in i2c mode.
If you want to use more than 2 BMP388 units with a single microcontroller, go with SPI. You can use as many BMP388 units as you have GPIO pins on microcontroller to control Slave Select pin.
This is the example from Adafruit BMPxxx library.
Here is permalink to the line where you can pass Slave Select (CS) pin of each unit to each unique object.
Later in the code you can use each object of the Adafruit BMPxxx library to get the readings.

Using Serial Peripheral Interface (SPI) to talk to several slaves simultaneously

I have four Atmega328p in a single board and I want one of them send the same data (i.e. sensor readings) to the other three simultaneously. I'm not interested in a bidirectional communication. I read this thread (How can I broadcast data to multiple SPI slaves and how it works?) about SPI broadcasting, and someone mentioned not being possible because in SPI communication is full duplex and MISO and MOSI lines are active at the same time. However, I was wondering if I could just let the MISO lines unconnected and all SS pins pulled low, so I could broadcast a message to all slaves simultaneosly, taking into account that I do not need any type of response from the slaves to the master.
So, is this possible? Or how else could I work around this problem? I was also considering on using UART's Tx line and connect all the receivers in parallel to it, but I'm not sure that would work too.
Thanks for your attention.

I2C COMMUNICATION

one micro-controller support all adc dac, spi, uart except I2C, but i want to use i2c communication.How to make i2c port using these protocol?
It would help if you told us which microcontroller you are using, and whether you need your micro to be an I2C master, a slave, or either.
If you just need to an I2C master, and you don't need to worry about other masters on the same bus (arbitration) or very slow slave devices (clock stretching), then I2C is very simple to implement using two GPIO pins. Search for " software i2c master" and you'll find things like I2C Implementation on 8051.
If you need to do arbitration because there may be multiple masters on the bus, or if you need to handle slave clock stretching, then read the I2C specification from Philips NXP. Take the simple code you find through Google and add the functionality you need.

Arduino Master-Slave Pin

Can I change the pins on the communication for a Master-Slave arduino Wire transmission? I want to communicate between 2 arduinos, but on one of them A4&A5 are taken
No, you can't change the pins used for I2C. They are hard wired to the ATmega chip's TWI hardware implementation (SDA + SCL). See Wire Library and Two Wire Serial Interface

Resources