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 Clk and Data lines

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



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

I2C Clk and Data lines
PostPosted: Mon Oct 09, 2006 10:47 am     Reply with quote

Just want to make sure that my thinking is correct that once the clock and data lines are defined there is no way to swap them. Our product depends on the user to make contact with the correct orientation and sometimes they use it upside down and so the clock and data lines are reversed. Just want to make sure that there is no way to get around this in firmware by swapping the lines.

I tried a small test and it did not work.

Code:

// intial setup of I2C
#use i2c(master, sda=I2C_SDA, scl=I2C_SCL, fast)

// if it appears that the I2C lines are swapped
#use i2c(master, sda=I2C_SCL, scl=I2C_SDA, fast)
// then change back to initial setting after finished reading.


I'm pretty sure that this is not possible, but wanted to know from the experts.


Thanks,

jspencer
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 11:52 am     Reply with quote

It's certainly possible, but you can't change the pins used by the
CCS library code at runtime. The code isn't written to do that.
You would have to create two instances of the device driver.
Each instance would be compiled to use the specified pins.

Also, you would have to rename the functions in the 2nd instance
of the device driver, so they wouldn't conflict with the 1st instance.
For example, let's take the CCS 24256.C eeprom driver.
It has these three functions:

init_ext_eeprom()
read_ext_eeprom()
write_ext_eeprom()

You could make a copy of the 24256.C file, and rename as
24256_swapped.c, or some other appropriate name. Then
within that file, rename all the functions and put in a #use i2c()
statement with the swapped pins.

Example:
#use i2c(master, sda=I2C_SCL, scl=I2C_SDA, fast)
init_ext_eeprom_swapped()
read_ext_eeprom_swapped()
write_ext_eeprom_swapped()

The "normal" (non-swapped) 24256.C file would look like this:
#use i2c(master, sda=I2C_SDA, scl=I2C_SCL, fast)
init_ext_eeprom()
read_ext_eeprom()
write_ext_eeprom()

In your main program, you would determine which driver to use
(normal or swapped), and then set a global flag to indicate this.
Then whenever you want to call the driver, you would check that
flag and call the appropriate routine. Example:

Code:

if(use_swapped_i2c_pins)
   write_ext_eeprom_swapped();
else
   write_ext_eeprom();


It's possible that you could also do it with function pointers.

---------

Edited to change one of the function names to init_ext_eeprom(),
as is shown in the driver file.


Last edited by PCM programmer on Tue Oct 10, 2006 4:58 pm; edited 1 time in total
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 12:22 pm     Reply with quote

Thanks PCM. That makes sense now. I've got the code space to add it in, so I'll give it a shot. If I have any questions I'll hollar. It would be a lot easier if the user would just RTFM! Reading the manual would solve a lot of problems.

jspencer
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Tue Oct 10, 2006 4:46 pm     Reply with quote

Thanks again PCM. That worked like a champ!
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