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 CCS Technical Support

I2c with 16f873 & 16f73

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







I2c with 16f873 & 16f73
PostPosted: Wed Mar 12, 2003 10:57 pm     Reply with quote

I am trying use Hardware I2c with 16F873 as master and 16F73 as slave but my code is not working. i have connected SCL & SDA pin of both the MCU's and also have 1K pull-up resistors in these pins. But my below code is not working. so can anyone point where i am making mistake

Thanks in Advance

SLAVE CODE

#include <16f73.h>
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT
#USE DELAY(CLOCK=4000000)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x10,FORCE_HW)
#byte portb=6

main()
{
byte data;
set_tris_b(0X00);
portb=0X00;
i2c_write(0x10); // slave address
data=i2c_read(); // read data
i2c_stop();
portb=data; // moving data to portb
delay_ms(1000);
}

MASTER CODE

#include <16f873.h>
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#USE DELAY(CLOCK=4000000)
#use i2c(master,SCL=PIN_C3,SDA=PIN_C4)
main()
{
i2c_start();
i2c_write(0x10); //address of slave
i2c_write(0x44); //data to slave
i2c_stop();
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12603
Tomi
Guest







Re: I2c with 16f873 & 16f73
PostPosted: Thu Mar 13, 2003 4:01 am     Reply with quote

Your slave code is incorrect. See the "ex_slave.c" for a correct I2C slave code.
Additionally, your master goes to sleep after i2c_stop(). Insert a while(1) cycle just after the stop call.

:=I am trying use Hardware I2c with 16F873 as master and 16F73 as slave but my code is not working. i have connected SCL & SDA pin of both the MCU's and also have 1K pull-up resistors in these pins. But my below code is not working. so can anyone point where i am making mistake
:=
:=Thanks in Advance
:=
:=SLAVE CODE
:=
:=#include <16f73.h>
:=#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT
:=#USE DELAY(CLOCK=4000000)
:=#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x10,FORCE_HW)
:=#byte portb=6
:=
:=main()
:={
:= byte data;
:= set_tris_b(0X00);
:= portb=0X00;
:= i2c_write(0x10); // slave address
:= data=i2c_read(); // read data
:= i2c_stop();
:= portb=data; // moving data to portb
:= delay_ms(1000);
:=}
:=
:=MASTER CODE
:=
:=#include <16f873.h>
:=#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
:=#USE DELAY(CLOCK=4000000)
:=#use i2c(master,SCL=PIN_C3,SDA=PIN_C4)
:=main()
:={
:= i2c_start();
:= i2c_write(0x10); //address of slave
:= i2c_write(0x44); //data to slave
:= i2c_stop();
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12609
balamagesh
Guest







Re: I2c with 16f873 & 16f73
PostPosted: Mon Mar 17, 2003 10:31 pm     Reply with quote

:=Your slave code is incorrect. See the "ex_slave.c" for a correct I2C slave code.
:=Additionally, your master goes to sleep after i2c_stop(). Insert a while(1) cycle just after the stop call.
:=

I am trying use Hardware I2c with 16F873 as master and 16F73 as slave.My code is working to some extent.But as per below slave code i am able to receive first address, then data and some hex code( i dont know what is it).How to make my master to send continously and my slave to receive continously. Pls help me in this regard.

i have connected SCL & SDA pin of both the MCU's and also have 1K pull-up resistors in these pins.

Thanks in Advance

SLAVE CODE

#include <16f73.h>
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT
#USE DELAY(CLOCK=4000000)
#use i2c(slave, SDA=PIN_C4, SCL=PIN_C3, address=0xa0,FORCE_HW)
#byte portb=6
main()
{
byte data;
set_tris_b(0X00);
portb=0X00;
data[0]=i2c_read(); // address of slave is received (0xa0)
portb=data[0];
delay_ms(2000);
data[1]=i2c_read(); // data is received (0x88)
portb=data[1];
delay_ms(1000);
data[2]=i2c_read(); // 0x40 is receieved
portb=data[2];
delay_ms(1000);
i2c_stop();
}

MASTER CODE

#include <16f873.h>
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT
#USE DELAY(CLOCK=4000000)
#use i2c(master,SCL=PIN_C3,SDA=PIN_C4,FORCE_HW)
#byte portb=6
main()
{
set_tris_b(0x00);
portb=0x00;
while(TRUE)
{
i2c_start();
i2c_write(0xa0); //address
i2c_write(0x88); //data
i2c_stop();
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12781
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