CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

i2C Communication Control

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
emaxxenon



Joined: 21 Jan 2020
Posts: 42

View user's profile Send private message

i2C Communication Control
PostPosted: Mon Mar 09, 2020 3:12 am     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 4:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 16, 2020 1:50 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group