|
|
View previous topic :: View next topic |
Author |
Message |
uNO
Joined: 18 Nov 2005 Posts: 10
|
i2c And pic 16f88 |
Posted: Fri Nov 18, 2005 2:13 pm |
|
|
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).
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
|
i2c |
Posted: Sat Nov 19, 2005 7:56 am |
|
|
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
|
|
Posted: Sat Nov 19, 2005 12:47 pm |
|
|
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
|
i2c |
Posted: Sun Nov 20, 2005 6:53 pm |
|
|
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 |
|
|
|
|
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
|