View previous topic :: View next topic |
Author |
Message |
emaxxenon
Joined: 21 Jan 2020 Posts: 42
|
i2C Communication Control |
Posted: Mon Mar 09, 2020 3:12 am |
|
|
Hi,
I am communicating with i2C. (pic: 18F25K22)
I have 10 slave cards (5 receiver - 5 transmitter).
The master card sends commands for them to operate ir leds.
But I want to see if the i2C communication is provided with LED.
When I do this way, the led is constantly on.
But if there is mutual communication, I want it to burn.
Is it possible to see mutual communication with LEDs without writing an additional command?
I don't want to send and receive separate information for control.
Code: |
//////////////////////////////////////////////////1.SLAVE///////
if(SW>=0)
{
//16 ir leds turn on respectively
for(int i=0; i<16; i++)
{
//Opening the receiver
i2c_start();
i2c_write(A_SLAVE1_W);
i2c_write(i);
i2c_stop();
//Opening the transmitter
i2c_start();
i2c_write(V_SLAVE1_W);
i2c_write(i);
i2c_stop();
delay_us(10);
}
//Reading information from the receiver
i2c_start();
i2c_write(A_SLAVE1_R);
A1_1 = i2c_read();
A1_2 = i2c_read(0);
i2c_stop();
//i2c communication led
output_toggle(pin_A0);
.
.
.
}
///////////////////////////////////////////////////////////////////////////////
|
Thanks in advance for your answers. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Mon Mar 09, 2020 4:06 am |
|
|
Look at the I2C bus scanner program in the code library.
When you send a command to a device that acknowledges it, the master
receives this acknowledge bit. The scanner program identifies that a device
is there and did acknowledge. Allows it to detect what devices are present.
You could use this to detect that the device is there are receiving on the
bus. |
|
|
emaxxenon
Joined: 21 Jan 2020 Posts: 42
|
|
Posted: Mon Mar 16, 2020 1:50 am |
|
|
Hello, thanks for answer.
I checked I2C debug.
If the address is incorrect, NAK = 1 appears. If true, 0 appears.
Is there a way to read this lice?
If the address is wrong, I want to turn on the led.
edit:
Code: | i2c_start();
status = i2c_write(address); // Status = 0 if got an ACK
i2c_stop();
if(status == 0)
return(TRUE);
else
return(FALSE);
} |
thanks in this way solved. |
|
|
|