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 support@ccsinfo.com

i2c And pic 16f88

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



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

i2c And pic 16f88
PostPosted: Fri Nov 18, 2005 2:13 pm     Reply with quote

Hi, I'm Trying to exchange data between two 16f88 connected on a i2c Bus.
To make a try I just used the two files Ex_slave.c and Ex_master.c. I've modified it only to configure them to use the 16f88.
I'use two pullup resitor (4,7k) on SDA and SCL

MASTER_SDA(B1)-----SLAVE_SDA(B1)------/\/\/\-----+5v

MASTER_SCL(B4)------SLAVE_SCL(B4)------/\/\/\------+5V

When I try to make it work I always read FF on the Emulated EEPROM (SLAVE PIC).Rolling Eyes

I've noticed that SCL is always LOW and SDA is always High but i can't guess why.

MASTER CODE

master.c


#include "master.h"
#include <input.c>
#include <2416.c>


void main() {
BYTE value, cmd;
EEPROM_ADDRESS address;
setup_oscillator(OSC_8MHZ | OSC_INTRC);

********************
Then the code from ccs
ex_master.c
********************
master.h

#include <16F88.h>
#fuses NOWDT,INTRC_IO, NOPUT, MCLR, BROWNOUT, LVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
#use i2c(Master,sda=PIN_B1,scl=PIN_B4,force_hw,slow)


SLAVE CODE
slave.c



********************
Ex_slave.c
********************

slave.h

#include <16F88.h>
#fuses NOWDT,INTRC_IO, NOPUT, MCLR, BROWNOUT, LVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
#use i2c(Slave,sda=PIN_B1,FORCE_HW,slow,scl=PIN_B4,address=0xa0)

In the laboratory where I'm working there is te version 3.236 of the compiler.

Please help me, I need it for an Experiment on artificial intelligence with the university.

Sorry for my very poor english.
Thank you
uNO



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

i2c
PostPosted: Sat Nov 19, 2005 7:56 am     Reply with quote

I made a mistake in my previous post , the file that I called EX_master.c is ex_extee.c.

I tried to use external clock, I'll get the output correctly on the screen via Serial port but always read FF on the emulated eprom.

I also tryed different values of pullìup resistor (4,7 | 1,8 | 2,3) but still nothing.

I'm quite sure that the circuit is well done, I've tryed some other code on the pic and all works great.

Please Help Me !!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 19, 2005 12:47 pm     Reply with quote

Quote:
#fuses NOWDT,INTRC_IO, NOPUT, MCLR, BROWNOUT, LVP,
NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO


First, here are some general comments:

1. Are you using a LVP programmer ? If not change the fuse to NOLVP
for each PIC.

2. You are using a software UART on both PICs. The 16F88 has a
hardware UART on pins RB5 and RB2 (Tx and Rx). If possible
you should use it instead of a soft UART.

With regard to fixing the problem:

I suggest that you first get it working with a real EEPROM chip as the
slave. This will prove that your master code is working. Then put
in the slave PIC and test it.
uNO



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

i2c
PostPosted: Sun Nov 20, 2005 6:53 pm     Reply with quote

Thank you PCM programmer, I removed the LVP flag.

I've found a solution, I've replaced the 4,7K with 10K pull-up resistors and used software i2c on the master

Code:
#include <16F88.h>
#fuses NOWDT,HS, NOPUT, MCLR, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
#use i2c(Master,sda=PIN_B1,scl=PIN_B4,force_sw,FAST=80000)


Now all works greatly but i don't know why Rolling Eyes
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