robert_terrell
Joined: 28 Jul 2004 Posts: 8
|
I2C PIC18F4550 Master PIC16F690 Slave |
Posted: Fri Jun 25, 2010 8:54 pm |
|
|
I'm sure I'm doing something stupid - that's usually the case. Can somebody spot what's wrong? It sits there and does nothing. The SCL line is low and the SDA line is high like the master is not getting an ACK? I know the errata says there is problem with the first clock pulse causing an over flow on the 690. I didn't really understand what to do, if anything about the errata on the 4550.
Slave PIC16F690
.h file
Code: |
#include <16F690.h>
//#device ICD=FALSE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES PUT //Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=1000000)
#define PGD1 PIN_A0
#define PGC1 PIN_A1
#define VPP1 PIN_A3
#define RXA PIN_A4
#define RXB PIN_A5
#define TX PIN_B5
#define RX PIN_B7
#define TXA PIN_C0
#define TXB PIN_C1
#define TXEN PIN_C3
#define RXEN PIN_C4
#define PWM PIN_C5
#use i2c(slave,sda=PIN_B4,scl=PIN_B6,address=0xa0,FORCE_HW) |
.c file
Code: |
#int_SSP
void SSP_isr(void) {
char state,add,incoming;
state=i2c_isr_state();
output_high(PIN_C6);
if(state<0x80){
output_high(PIN_C7);
incoming=i2c_read();
if(state==0){add=incoming;output_high(PIN_C6);}
if(state==1){duty=incoming;output_high(PIN_C7);}
}
if(state==0x80){add=i2c_read();i2c_write(0xff);}
if(state>0x80){i2c_write(0xff);}
}
|
Master Code
PIC18F4550
The files are big so I'll just post the parts I think are worth looking at but then again I'm missing something.
.h
Code: |
#use i2c(master, SCL=PIN_B1, SDA=PIN_B0, force_hw)
|
.c
Code: |
void write_i2c(int add,int data){
i2c_start();
i2c_write(add);
i2c_write(data);
i2c_stop();
}
|
I have 4.7K pullups - is that too much?
Thank You |
|