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

How to use i2c with PIC16F84A and PIC12F675 ?

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







How to use i2c with PIC16F84A and PIC12F675 ?
PostPosted: Sun Jan 22, 2006 4:36 am     Reply with quote

i'm use 16F84A is master and use 12F675 is slave.
master connect with mmc card via rs232.
my master will read parameter from slave and keep parameter to temp and then pass that value to mmc card.
i'm wanna to know how stretegy to read and write.
Thanks.
Adek
Guest







PostPosted: Sun Jan 22, 2006 1:08 pm     Reply with quote

This is main of slave.
/***********************************************************/
void main(void)
{
int16 value;
int i;
float volt;
char val[9];

setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);

value = Read_ADC();
volt = Vbe * (float) value;
sprintf(val,"<%0.5f>",volt);
for(i=0;i<7;i++)
i2c_write(val[i]);
delay_ms(1);
}
/***********************************************************/
and this main of master.
/***********************************************************/
#use i2c(master, sda=PIN_A0, scl=PIN_A1)
#use rs232 ( baud=9600, xmit=TxD, rcv=RxD, stream=memory)
void main()
{
char tmp[12];
char begin[4] ={0x0A,0x0D,0x3E};
char write[3] =":";
char fmane[13]="TEST0001.TXT";
char val_sen;
int i,j,k,l,test;

while (!kbhit());
for(i=0;i<3;i++) tmp[i]=getc();
for(j=0;j<3;j++) if(tmp[j]!=begin[j])reset_cpu();

putc('W');

while(!kbhit());
for(k=0;k<1;k++) tmp[k]=getc();
for(k=0;k<1;k++) if(tmp[k]==write[k]) test=1;
for(l=0;l<12;l++) putc(fmane[l]);

putc(13);

while(TRUE)
{ i2c_start();
i2c_write(0x01);
for(i=0;i<7;i++)
tmp[i] = i2c_read();
i2c_stop();
putc(',');
for(i=0;i<7;i++)
putc(tmp[i]);
delay_ms(1);
}
}
/***********************************************************/

Now it can write file to mmc card, but data put to mmc card it wrong.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 23, 2006 1:06 am     Reply with quote

In the following thread, they discuss the reasons why a hardware SSP
module is needed for an i2c slave:
http://www.ccsinfo.com/forum/viewtopic.php?t=23177
Your two PICs don't have a hardware SSP module.
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