SB
Joined: 15 Jan 2004 Posts: 10
|
I2C Slave problems with a PIC18F6622 |
Posted: Tue Jan 22, 2008 11:37 am |
|
|
I am using the Ex_slave.c example on a Pic18F6622 with a Diolan USB to I2C interface adapter.
I am unable to read from the Pic, the Diolan times out and reports that the Slave has dropped the SDA and SCL lines.
I have tried using the second I2C on the pic with the same results.
I can program some DAC's which I have on the second I2c via the Diolan adapter so I am pretty sure that my hardware is ok.
I have tried the same code with a Pic16F88 and the Diolan adapter and it works without any problems.
Has anyone used the 18F6622 as an I2C slave?
(I am using PCWH V3.234)
Code: |
#include <18F6622.h>
#device adc=10
#FUSES NOWDT
#FUSES WDT128
#FUSES INTRC_IO
#FUSES NOPROTECT
#FUSES IESO
#FUSES BROWNOUT
#FUSES BORV25
#FUSES NOPUT
#FUSES NOCPD
#FUSES STVREN
#FUSES NODEBUG
#FUSES NOLVP
#FUSES NOWRT
#FUSES NOCPB
#FUSES NOEBTRB
#FUSES NOEBTR
#FUSES NOWRTD
#FUSES NOWRTC
#FUSES NOWRTB
#FUSES FCMEN
#FUSES LPT1OSC
#FUSES NOMCLR
#FUSES NOXINST
#FUSES BBSIZ1K
#use delay(clock=8000000)
#use i2c(Slave,sda=PIN_C4,scl=PIN_C3,address=0xa0,force_hw)
BYTE address;
BYTE buffer[0x10] = {1,2,3,4,5,6,7,8,9,0};
#INT_SSP
void ssp_interupt ()
{
int8 incoming;
int8 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(AN0_TO_AN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_wdt(WDT_OFF);
setup_timer_1(T1_DISABLED);
set_timer1(64535);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while(TRUE)
{
restart_wdt();
}
}
|
|
|