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

Change I2C Master to I2C Slave On the Fly

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



Joined: 08 Sep 2003
Posts: 5

View user's profile Send private message

Change I2C Master to I2C Slave On the Fly
PostPosted: Wed Apr 06, 2005 4:40 am     Reply with quote

Hi,all. I have an application requirement on a PIC18F452 board. This board using a IO pin[defined as #define MASTER_I2C input(PIN_B3)] to determine whether it should be a I2C master or I2C slave.



Code:

int1 Check_Mode(Void)
{
    if (MASTER_I2C)
    {
       Master_Flag=TRUE;
       #use i2c(master, sda=PIN_C4, scl=PIN_C3,FORCE_HW)
       //InitI2C();
    }
    else
    {
      Master_Flag=FALSE;
      #use i2c(slave, sda=PIN_C4, scl=PIN_C3,address=0x90,FORCE_HW)  // Default Base Address
      get_i2c_slave_addr(); // return my_slave_addr
      SSPADD = my_slave_addr;
      InitI2C();
      enable_interrupts(int_ssp);
    }
    return(Master_Flag)
}




I called the check_mode() in my main code, before the loop. For testing, I enable the board for master mode. I just do a series of I2c_start(), i2cwrite(Data1)
,i2c_write(data2), i2c_stop() inside the while(1) loop.

When I monitor the SDA and SCL line (these lines have 4.7K pullups), the lines stays at all times HIGH!!. No I2C packets on my scope.

When I commented out the check_mode and hardcode the #use i2c statement at the beginning of my code, the hardware works instantly!


Question: Can we really change the #use I2C on the fly, by choice of a Mode Selection PIN? I would really appreciated if someone helps

Warmest Regards

lguancho

[/quote]
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 06, 2005 8:19 am     Reply with quote

You can definitely switch between master and slave. Take a look at my code in the Code Library. I didn't use the #use, instead, I set it up manually.
lguancho



Joined: 08 Sep 2003
Posts: 5

View user's profile Send private message

Change I2C Master to I2C Slave on the Fly
PostPosted: Thu Apr 07, 2005 8:03 pm     Reply with quote

Hi, Mark. Saw your code before. I am going to try it. Thanks

lguancho
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