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 slave operation

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



Joined: 17 Aug 2005
Posts: 4
Location: Livermore, CA

View user's profile Send private message

i2c slave operation
PostPosted: Wed Aug 17, 2005 11:07 am     Reply with quote

I am attempting to use a 16f767 as an i2c slave. The address for the slave is set to 0x21. I am using an Aardvark i2c interface module to communicate with the PIC. When I send data to the PIC at address 0x21, there is no response. If I change the address that the interface module sends the data to 0x10, the PIC responds as expected. If I change the PIC's address to a different value, I don't get any response. When I check the values of the internal registers with MPLAB: register 0x14 (sspcon) = 0x36, register 0x91(sspcon2) = 0 and 0x93 (i2c addr) = 0x21. The same problem occurs when I use the ex_slave.c example or my code. When I use a scope to monitor the scl and sda lines, they seem to be correct.

Any ideas?

Main Program

#include "C:\Program Files\PICC\Projects\Bio_Briefcase\i2c_0816.h"
#int_SSP
SSP_isr()
{

int incoming;

if (i2c_poll() == TRUE) {
incoming = i2c_read();

if (incoming == 0x21) {

output_low(pin_a0);
delay_us(200);
output_high(pin_a0);
delay_us(200);
output_low(pin_a0);
delay_us(200);


}

}
}



void main()
{

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
setup_oscillator(False);

while (true){

output_high(pin_a0);

}

}


.h file

#include <16F767.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES EC_IO //External clock
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES MCLR //Master Clear pin enabled
#FUSES DEBUG //Debug mode for ICD
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BORSEN //See Datasheet

#use delay(clock=20000000)
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,address=0x21)
Ttelmah
Guest







PostPosted: Wed Aug 17, 2005 2:36 pm     Reply with quote

Remember an I2C address can only occupy the upper 7bits. The low bit of the address byte is reserved for the direction control, and will be changed by the code.
0x20 is a legitimate address, but not 0x21...

Best Wishes
ddscott



Joined: 17 Aug 2005
Posts: 4
Location: Livermore, CA

View user's profile Send private message

PostPosted: Wed Aug 17, 2005 4:53 pm     Reply with quote

Thanks for the help. I came to the same conclusion about the time I opened my email. What was also confusing was that to get the PIC to respond to an address call of 0x20 from the emulator, you have to give the PIC an address of 0x40.

Thanks again.
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