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 support@ccsinfo.com

I2C i/o expander

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



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

I2C i/o expander
PostPosted: Thu Aug 19, 2010 6:18 am     Reply with quote

Hi,

I'm looking for an i/o expander that is controlled by i2c and has the option to invidually set the pins to in or out.
Is there any example files out there?
I'm in need of 8-10 i/o's

Thanks
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 6:34 am     Reply with quote

2 questions :-

1. what has this got to do with the CCS C compiler


2. are you incapable of googling "I2C i/o expander"


try PCF8574
SveinR



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 6:53 am     Reply with quote

MikeW wrote:
2 questions :-

1. what has this got to do with the CCS C compiler


2. are you incapable of googling "I2C i/o expander"


try PCF8574


I need and example file showing how to setup this i/o expander,
and as I'm aware of there is no include file for the PCF8574 included in the CCS package that I got.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 7:03 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=19526&highlight=pcf8574

Humberto
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 7:11 am     Reply with quote

PCF8575 is a 16 i/o device

Code:



#define PCF8575_device_type 0x40

// pcf8575 device numbers go from0 -number of devices

void  Test_IO_Module()
{
int16 PCF8575_Data_Word;


Digital_Inputs_from_PCF8575=read_PCF8575(0);   // get the digital input states
Display_Digital_Input_Values(~Digital_Inputs_from_PCF8575);
} // end of function

// functions



// this is a handy function for taking the i2c physical address
// and shifting the bits left so that the address can simply be
// OR'd with an i2c write command...

int i2c_addr_mask(int device_addr)
{
   /* xxxxxIJK --> 00000IJK, then 00000IJK --> 0000IJK0 */
   return((device_addr & 0x07)<<1);
} // end of function


#define I2CWRITE     0b00000000
#define I2CREAD      0b00000001



void write_PCF8575(BYTE device_address, WORD data)
{

BYTE Upper_Data_Byte;
BYTE Lower_Data_Byte;
BYTE addr_mask;
BYTE address;


   addr_mask=i2c_addr_mask(device_address);
   i2c_start();
   Upper_Data_Byte=make8(data,1);
   Lower_Data_Byte=make8(data,0);
   i2c_start();
   address=(PCF8575_device_type | addr_mask | I2CWRITE);
   i2c_write(address);
   i2c_write(lower_Data_Byte); // LSB 1 is input mode
   i2c_write(~Upper_Data_Byte); // MSB 1 is OFF , inverted 'cos of the HC240
   i2c_stop();


} // end of function

int16 read_PCF8575(BYTE device_address)
{

BYTE Upper_Data_Byte;
BYTE Lower_Data_Byte;
BYTE addr_mask;
BYTE address;

   addr_mask=i2c_addr_mask(device_address);
   i2c_start();
   address=(PCF8575_device_type | addr_mask | I2CREAD);
   i2c_write(address);
   Lower_Data_Byte=i2c_read(); // LSB get the byte
   Upper_Data_Byte=i2c_read(0); // MSB get the byte

   i2c_stop();
   return (make16(Upper_Data_Byte,Lower_Data_Byte));

} // end of function

SveinR



Joined: 04 Aug 2005
Posts: 9

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 7:24 am     Reply with quote

Thanks all Very Happy
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