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

two I2c i/f....slave is problemetic

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



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

two I2c i/f....slave is problemetic
PostPosted: Wed Apr 04, 2007 7:01 am     Reply with quote

I am using a PIC as a I2C bridge...

for slave, i am using hardware and for master I am using software I2c..
software one is working fine....
while the hardware I2C is not working properly...
this is the code for HW..
once master accumlates the data, it will store and pass it to slave hw interface...

//===================
#INT_SSP
void i2c_interrupt_handler(void) // Interrupt handler for slave I2C
{
#use i2c(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x60, FORCE_HW)
BYTE state;
state = i2c_isr_state();

if(state == 0x80) // Master is requesting data
{
for (i=0;i<4>>; // High byte of command
}
}
else if(state < 0x80) // Master is sending data
{
recvx = i2c_read();
ADC_store[1] = recvx;
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 04, 2007 11:18 am     Reply with quote

Your code is unreadable because you had HTML enabled when you
posted it. Also, I can tell from your placement of the #use i2c()
statement that you're new to CCS. You need to study the example
files. You need to start by using the example files instead of your own
code. That way, you can make something that works and learn from it.
Once you've done that, you can start creating your own code.

Suggestions:
Put the Ex_Slave.c program into your slave PIC.
That example file is in this folder: c:\Program Files\PICC\Examples

Use the code in this post for your Master PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=28097&start=9

This should work. It will also tell you if your hardware is working OK.
For example, do you have pull-ups on the SDA and SCL lines ?
Do you have a ground connection between the two boards ?
tom_hanks



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

thanks
PostPosted: Thu Apr 05, 2007 9:36 am     Reply with quote

HI PCM,
Thank you....

you helped me out with 60 % solution..

I am using Master and slave both together on My PIC...
if I use master only then it works, or only Slave code....

but when i tried to use both Master & slave...it clashes...
and transaction happens on slave side of PIC....

here is my code..
Code:


#use i2c(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x60, FORCE_HW)
      
#INT_SSP
void i2c_interrupt_handler(void)
   {
   BYTE   state,incoming;
   state = i2c_isr_state();

   if(state < 0x80)      
      {
      incoming = i2c_read();
      }
   if(state == 0x80)
      i2c_write(0x6B);
}


void main(void)
{
printf("Hello World\n");            // Say hello
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
#use i2c(MASTER, SDA=PIN_B2, SCL=PIN_B3)     
i2c_start();               
i2c_write(I2C_ADC);
i2c_write(SETUP_ADC);
i2c_write(CONFIG_ADC);
i2c_stop();
    while(1)
      {
         i=0;
         i2c_start();
         i2c_write(I2C_ADC+1);               
         while (i!=8)                      
         {
         ADC_res.Isense[i] = (i2c_read());
         printf("\rAD%d=%x\t",i,ADC_res.Isense[i]); 
         i++;
         }
         i2c_stop();
   output_toggle(PIN_A2);
   restart_wdt();
      }
}
Ttelmah
Guest







PostPosted: Thu Apr 05, 2007 9:57 am     Reply with quote

What chip?.

Best Wishes
tom_hanks



Joined: 04 Apr 2007
Posts: 20

View user's profile Send private message

PostPosted: Thu Apr 05, 2007 9:59 am     Reply with quote

PIC16F818

for slave:
Hardware I2C

for Master:
Software I2C

any one out there ??
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