View previous topic :: View next topic |
Author |
Message |
TM_F88
Joined: 08 Apr 2010 Posts: 2
|
problem i2c slave 16F88 (NACK!) (EX_SLAVE.C) |
Posted: Thu Apr 08, 2010 4:08 am |
|
|
Hi i'm trying to comunicate 2 pics via i2c.
MASTER:
- The master is 18F452 and implements software i2c (also is using the microchip TCP/IP stack)
- The master comunicates OK with other devices (SRF08 ultrasonic sensor)
- The clock frequency is 100Khz (bus speed)
- Pull-up resistors 10k
SLAVE:
- I'm using the ex_slave.c example in CCS (version 4.023)
- Pic 16F88 running at 20MHz
- Using HW i2c
- The LED blinks ok, so the pic is not locked.
PROBLEM DESCRIPTION:
- When the master tries to write, the slave ack correctly the address byte (i'm sure about this). The last 2 bytes (data bytes) the slave gives a NACK.
- I think that SSP interrupt never reaches.
The slave code:
Code: |
#include <16F88.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use i2c(SLAVE,FORCE_HW, SDA=PIN_B1,SCL=PIN_B4,address=0xA0)
#define LED_GROC_ON() output_high(PIN_B0)
#define LED_GROC_OFF() output_low(PIN_B0)
BYTE address, buffer[0x10];
BYTE interrup;
#INT_SSP
void ssp_ISR (void)
{
BYTE incoming, state;
interrup = 1;
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(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_b(0b11111110);
LED_GROC_OFF();
interrup = 0;
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
delay_ms(10);
while(1){
delay_ms(1000);
LED_GROC_OFF();
delay_ms(1000);
LED_GROC_ON();
}
}
|
Any suggestions to solve the problem? Could the 16F88 or the compiler have any bug? I'm almost sure that the problem remains on the slave.
Thanks for your help!! |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Apr 08, 2010 5:20 am |
|
|
Quote: | CCS (version 4.023) | Whenever I read about a version 4 compiler before v4.070 I stop reading.
Upgrade your compiler to a more recent version, or downgrade to the stable v3.249 that was available at the time of your download. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 08, 2010 10:53 am |
|
|
Your version may have problems because it is an early version.
But assuming that it might work, here's what you can do:
First, try to get a simple i2c slave program working.
When you get that working, then try to make your own program work.
Use the CCS example file code, Ex_Slave.c, for the Slave PIC.
It's in this directory:
Quote: |
c:\Program Files\picc\Examples\Ex_Slave.c
|
Use the code in this post for the Master PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=32368&start=3
Make sure that you have the 4.7K pull-up resistors on both SDA and SCL. |
|
![](templates/subSilver/images/spacer.gif) |
TM_F88
Joined: 08 Apr 2010 Posts: 2
|
|
Posted: Thu Apr 08, 2010 12:24 pm |
|
|
Hi guys!! I've upgraded the compiler version to 4.093 and now it works perfect!!!
Thanks, thanks and more thanks!! I've wasted many time on this! =D |
|
![](templates/subSilver/images/spacer.gif) |
|