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 address with software

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







change i2c address with software
PostPosted: Fri Jun 11, 2004 8:24 am     Reply with quote

Hi,
I have a 18F458 a microswitch on PORTD.
I wont change the address of I2C via software but the compiler send me an error.

Code:

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb4, fast,FORCE_HW)



How I can change the parameter address ???

Regards Mirko
Ttelmah
Guest







Re: change i2c address with software
PostPosted: Fri Jun 11, 2004 8:38 am     Reply with quote

mirberti wrote:
Hi,
I have a 18F458 a microswitch on PORTD.
I wont change the address of I2C via software but the compiler send me an error.

Code:

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb4, fast,FORCE_HW)



How I can change the parameter address ???

Regards Mirko

The line you post should work fine.
It is quite common for error messages to appear on a line, when the fault is actually somewhere just in front of this point. Remember the device selection, and #use_delay declaration need to be before this line.

Best Wishes
mirberti
Guest







PostPosted: Fri Jun 11, 2004 8:55 am     Reply with quote

My complete start code is :
Code:

#include <18F458.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,WDT1,NOLVP
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb4, fast,FORCE_HW)


now, if I use this code all is OK but I wont change this code for permit to change my i2c address by a dip-switch.
How can I change it ?

Mirko
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jun 11, 2004 9:29 am     Reply with quote

Here is what I have done with one of my projects. The base address of the Slave is 0x90. I use four inputs to modify the address if needed.

Code:

#use i2c(Slave,fast,sda=PIN_B1,scl=PIN_B4,restart_wdt,address=0x90)

#byte SSPADD = 0x93 // Slave address register

unsigned int8 slave_addr = 0x90;// base address for all slaves is 0x90


main(void)
{
   get_add();
   SSPADD = slave_addr;

   while(1)
   {
      *main body*
   }
}

void get_add(void)            // possible combinations
{// base address is 0x90   0x90 92 94 96 98 9A 9C 9E A0 A2  BASE:1001 0000

   if(input(PIN_A0))      //  0  1  0  1  0  1  0  1  0  1
   {
      bit_set(SLAVE_ADDR, 1);
   }

   if(input(PIN_A7))//        0  0  1  1  0  0  1  1  0  0
   {
      bit_set(SLAVE_ADDR, 2);
   }

   if(input(PIN_A6))//        0  0  0  0  1  1  1  1  0  0
   {
      bit_set(SLAVE_ADDR, 3);
   }

   if(input(PIN_B7))//        0  0  0  0  0  0  0  0  1  1
   {
      bit_clear(SLAVE_ADDR, 4);
      bit_set(SLAVE_ADDR, 5);
   }
}// end of get_add()

Ttelmah
Guest







PostPosted: Fri Jun 11, 2004 10:04 am     Reply with quote

mirberti wrote:
My complete start code is :
Code:

#include <18F458.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,WDT1,NOLVP
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb4, fast,FORCE_HW)


now, if I use this code all is OK but I wont change this code for permit to change my i2c address by a dip-switch.
How can I change it ?

Mirko

It is possible that the I2C setup, works like the RS232 one. If so, then this should work:
Code:

switch (input & 3) {
   case 0:
      #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb4
      break;
   case 1:
      #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb5
      break;
   case 2:
      #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb6
      break;
   case 3:
      #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xb7
      break;
}

In the case of RS232, this type of construction had to be used before the seperate baud rate control functions, an 'streams' were introduced, and the compiler applies the last such function 'passed' in the normal flow. Whether this works with I2C, I cannot say for sure. It is worth a try.
However if you want a lot of possible addresses, do a single #use_i2c, with a 'default' address, and use:
Code:

#byte I2C_ADDRESS = 0xFC8

I2C_ADDRESS=(0xB0 + input);

Where 'input' is a variable carrying perhaps a three bit address.

Best Wishes
mirberti
Guest







PostPosted: Fri Jun 11, 2004 10:08 am     Reply with quote

thanks a lot. I try now youre solution

hi Mirko
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