|
|
View previous topic :: View next topic |
Author |
Message |
Mark Weir
Joined: 11 Sep 2003 Posts: 51 Location: New Zealand
|
|
Posted: Wed Aug 08, 2007 2:08 pm |
|
|
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
|
Got It |
Posted: Wed Aug 08, 2007 2:50 pm |
|
|
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
|
|
Posted: Wed Aug 08, 2007 2:56 pm |
|
|
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
|
Test Program |
Posted: Wed Aug 08, 2007 3:13 pm |
|
|
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
|
|
Posted: Wed Aug 08, 2007 3:29 pm |
|
|
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
|
|
Posted: Wed Aug 08, 2007 3:57 pm |
|
|
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
|
|
Posted: Thu Jan 17, 2008 3:01 am |
|
|
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.. |
|
|
|
|
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
|