In I2C bus, how slave devices knows data belongs to them or not - microcontroller

I have one micro controller and 4 slave devices are attached with micro controller I2C bus. I have one doubt regarding data reading from I2C bus. When master initiates any transmission it will write device address on the I2C bus, but i want to know how slave devices will identify in I2C bus, data belongs to them or not.

Slave devices have an address, either a fixed one or often an address where one or two bits can be configured by hardware (pulling certain pins of the chip to ground or VCC). Each slave knows its own address.
The slaves listen to all I2C communication. If an I2C transaction contains their address at the start, they will interact in the transaction. Otherwise they will ignore the transaction.

Related

How to scan I2C slave address on STM32?

I'm trying to communicate with an mpu9250 with STM32 via I2C, but I can't determine the slave address. (I am using a usb bootloader.)
According to the datasheet
(https://www.invensense.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf)
page 12,
the default I²C slave address of the MPU9250 is 0b1101000(=0x68=104) or 0b1101001(=0x69=105) depending on the value of pin AD0.
If you use two MPU9250, you can differentiate them by using one with the first address and the other one with the other address by putting a logic LOW on the AD0 pin of the first MPU and a logic HIGH on the AD0 pin of the second MPU.

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.

I2C SCL line, clock issue on STM32F4

In I2C interface,
SCL, clock line will transmit clock signals even if there are no devices on the bus?
How can we debug the I2C?
The I2C bus master does not know if there are slave devices connected to the bus.
All it can do is to initiate communication with a certain device by sending the slave's address to the bus (it can be a read or write operation). If the master receives an ACK, acknowledge, then that means the slave is ready (and presented on the bus) to communicate. A NACK, not acknowledge can mean that the slave is not ready. If the request time outs that means, there is no available devices on the bus with the specific address.
Now, back to your question:
SCL, clock line will transmit clock signals even if there are no devices on the bus?
Yes, the clock line will be driven when the master initiates the communication, even if there are not any slaves. The clock is used, as there are data on the bus, the slave device address.
It looks like in the image below, the only difference that the ACK won't be there if there are no slave device on the bus (with that address).
Now as for the debug, the best would be if you could buy a logic analyzer, (cheaper versions are available on eBay or aliexpress) to capture what is going on actually on the bus. The image above has been made using one.

2 channels I2C for Atmega328

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.

Resources