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

I2C PIC18F4550 Master PIC16F690 Slave

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



Joined: 28 Jul 2004
Posts: 8

View user's profile Send private message

I2C PIC18F4550 Master PIC16F690 Slave
PostPosted: Fri Jun 25, 2010 8:54 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 25, 2010 10:59 pm     Reply with quote

Post a short, complete test program for the Master. I can see part of
what's wrong in your slave isr, but I need to see the Master routine
that reads from the slave (you only posted the write routine). I also
need to see how you call the read and write routines in the Master.

This is an example of a short program for the Master:
http://www.ccsinfo.com/forum/viewtopic.php?t=32368&start=3


Also post your compiler version.
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