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

16F886 I2C
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 2:08 pm     Reply with quote

No joy sorry PCM,

I included this fix but we still have the problem. Out of curiosity I asked CCS Support if they had done any testing on this part in the slave mode. They say not and had just assumed that as the I2C module was similar to other devices it would work so we dont know if it even will work.
I asked what ther word" slave " does, the answer was that it sets up the pic to receive clocks rather than produce them.

Any other thoughts? something else I can try?
_________________
Life is too short to avoid asking questions
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

Got It
PostPosted: Wed Aug 08, 2007 2:50 pm     Reply with quote

It had to something simple!

I needed this :
setup_spi(SPI_SS_DISABLED); in the setup.
I had created the project with the PIC Wizard and this did not come through.

Thanks for you help
_________________
Life is too short to avoid asking questions
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 2:56 pm     Reply with quote

1. Can you post the test program that you use for the 16F876 ?
Post the working slave code that you've actually tested.

2. For the 16F886 board, if you program it with the Slave code and
power it up, but don't connect it to the Master board or to any
i2c cable, are the SCL and SDA lines still held low on it ?
In other words, does it show the failure mode all by itself, with
no connection to the outside world ?

3. Try enabling the PUT and BROWNOUT fuses.

4. Do you know for sure that the boards that have the 16F886 on them
haven't been "rev'ed" by another department in your company, and
maybe they crossed the SCL and SDA lines, and didn't tell anyone,
or something of that sort.

5. Have you tried using the 16F886 board as an i2c Master ?
Does it work ?
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

Test Program
PostPosted: Wed Aug 08, 2007 3:13 pm     Reply with quote

For the 876A
Code:

///////////////////////////////////////////////////////////////////////////
////                         Slave1_876.C                               
////                                                                 
////  This program uses the PIC in I2C  SLAVE MODE   
////    ADDRESS A0
////
///////////////////////////////////////////////////////////////////////////

#include <16F876A.h>

#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                           //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                      //Master Clear
#FUSES NOPROTECT             //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT         //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16)
#FUSES NODEBUG                 //No Debug mode for ICD
#FUSES NOWRT                   //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,address=0xA0)


BYTE address, buffer[0x10];

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         buffer[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
}

void main ()
{
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_SSP);
   
   

   while (1) {
      
    output_toggle(Pin_B2);
      delay_mS(100);
      
      }
}

For the 252
Code:

///////////////////////////////////////////////////////////////////////////
////                         Slave_1_252.C                               
////                                                                 
////  This program uses the PIC in I2C SLAVE MODE
////      ADDRESS A2
////
///////////////////////////////////////////////////////////////////////////

#include <18F252.h>

#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                           //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                      //Master Clear pin used for I/O
#FUSES NOPROTECT             //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT         //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16)
#FUSES DEBUG                    // Debug mode for ICD
#FUSES NOWRT                   //Program memory not write protected


#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,address=0xA2)


BYTE address, buffer[0x10];

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
         buffer[address] = incoming;
   }
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
}

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

   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_SSP);
   
   

   while (1) {
      
    output_toggle(Pin_B2);
      delay_mS(100);
      
      }
}


I retested the 886 board as you describe. With no outside connections the Data line stays low and the Clock line goes high. There are no pullups on the slave boards. I am certain about the boards, there are only 2 of us here that have any dealings with pcbs and we use these boards all the time.

PS I just reprogrammed the 886 and it has stalled again.

Oh well back to it.
_________________
Life is too short to avoid asking questions
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 3:29 pm     Reply with quote

Quote:
#include <16F876A.h>

#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16)
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected

This PIC doesn't have an MCLR fuse. This program won't compile.
In your orginal post, you said you were using an 16F876. But in this
post it's a 16F876A. There are differences between the chips. For
example, the "A" chip has comparators, but the "non-A" chip does not.
Mark Weir



Joined: 11 Sep 2003
Posts: 51
Location: New Zealand

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 3:57 pm     Reply with quote

sorry, got my versions mixed up. It is an 876a and you will see I have taken care of the comparator disabling.
_________________
Life is too short to avoid asking questions
16f886 i2c not work
Guest







PostPosted: Thu Jan 17, 2008 3:01 am     Reply with quote

Hey guys,
Did you guys came up with the solution to let the 16F886 i2c to work as a slave?
I'm facing the problem too..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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