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

I/O expander

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



Joined: 09 Sep 2005
Posts: 36

View user's profile Send private message

I/O expander
PostPosted: Mon Sep 26, 2005 4:57 am     Reply with quote

i have a max7313 , 16 port i/o expander with led intensity control , to use in my rgb led project. i ve learned the process of i2c communication and i should know how i can use this i/o expander as a slave device. do i have to write a slave interrupt routine or driver for the device by myself, or use a universal device programmer or just send the register addresses and pwm values by master??
thanks
Mark



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

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

PostPosted: Mon Sep 26, 2005 6:21 am     Reply with quote

The MAX7113 will be the slave device. There is no need for your PIC to have a slave interrupt routine. If you read the datasheet for the MAX7313, it will state the address and register values needed to control the IO. Then take a look at one of the I2C eeprom examples (2401.c). You can modify one of those to write your values.
asunca



Joined: 09 Sep 2005
Posts: 36

View user's profile Send private message

PostPosted: Tue Sep 27, 2005 8:34 am     Reply with quote

i ve modified the extee example and used 2401.c file. and i ve written my driver code for max7313. when i was struggling with two pics communicating,i knew which step i was on, but now i dont know what happens inside the maxim.. master transmits the codes according to my readings of datasheet but nothing happens... max7313 stays at the initial power up configuration, outputs are hi-Z. what is hard is the maxim has more complex inside addressing than eeprom.

slave address+ command address(internal register address)+ data byte

that is the process for writing to maxim..
ithink i should swallow the datasheet ... again...
Mark



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

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

PostPosted: Tue Sep 27, 2005 8:40 am     Reply with quote

Post your code.
asunca



Joined: 09 Sep 2005
Posts: 36

View user's profile Send private message

PostPosted: Wed Sep 28, 2005 4:52 am     Reply with quote

i dont know what is going on inside this microprocessor and i have no idea about how isr is done inside it...
and extra thing; the scl line stays at 2.2V and sda line stays at 1.4V when i use slave_ready() function..


i ve found out that ,when i try a simple code whether the maxim will acknowledge my command. it cannot acknowledge.. here is the try

void try()
{
if (slave_ready(0x10)) output_high(pin_b7); // slave address is 0x10
}


here is the driver code for max7313:

Code:



#ifndef slave_SDA

#define slave_SDA  PIN_C4
#define slave_SCL  PIN_C3

#endif

#use i2c(master,sda=slave_SDA, scl=slave_SCL)


void init_slaves()
{
   output_float(slave_SCL);
   output_float(slave_SDA);
}

BOOLEAN slave_ready(int address)
{
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write((address>>7) & 0xfe);  // then the device is ready.
   i2c_stop();
   return !ack;
}

void write_slave(int address,int command,int data)
{
   //while(!slave_ready(address)); // if i usethis line sda and scl are wrong
   i2c_start();
   delay_ms(15);
   i2c_write( (address>>7) & 0xfe);
   delay_ms(15);
   i2c_write(command);
   delay_ms(15);
   i2c_write(data);
   delay_ms(15);
   i2c_stop();
}
void configure_slave(int address)
{
   write_slave(address,0x06,0x00);  // port configuration registers
   write_slave(address,0x07,0x00);  // port configuration registers
   write_slave(address,0x0F,0x00);  // Configuration register settings
   write_slave(address,0x0E,0x80);  // master intensity 8/15 oraninda
   write_slave(address,0x02,0xFF);  // outputs are set to high
   write_slave(address,0x03,0xFF);  // outputs are set to high
}


/////////////////////////////////////////////////////////////////////////////////////////////////
/*BOOLEAN ext_eeprom_ready()
{
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0xa0);  // then the device is ready.
   i2c_stop();
   return !ack;
}*/

/*void write_slave(int address, BYTE data) {
   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
}*/


/*BYTE read_ext_eeprom(long int address) {
   BYTE data;

   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))&0xfe);
   i2c_write(address);
   i2c_start();
   i2c_write((0xa0|(BYTE)(address>>7))|1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}*/



and the main program iis dedicated to give diffrent pwms to rgb leds. for the color pink, the commands are transmitted....

Code:


#include <16F877.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use i2c(Master,sda=PIN_C4,scl=PIN_C3)

#include <max7313.c>


void pink()
{
   configure_slave(0x10);
   delay_ms(5);
   write_slave(0x10,0x10,0xF6);       // red, green
   write_slave(0x10,0x10,0x0F);       // blue
}


void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   init_slaves();
   delay_ms(20);


   pink();

   while(1);
}

[/code]
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