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

help transfer data from slave to master

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



Joined: 12 Mar 2013
Posts: 1

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

help transfer data from slave to master
PostPosted: Tue Mar 12, 2013 2:30 am     Reply with quote

for example I want to pass the number 5 from the master to the slave, then the slave to send the number 5 for the master and the owner is the value that the port B, write code and simulation on protues it all fails.
your code is correct for me with:
code:
//master
#include <16F877A.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use Delay(Clock=20000000)
#use i2c(master, sda=PIN_C4, scl=PIN_C3)
int8 value_re1,n;
void write_I2C(int8 value1,int8 slave_addr)
{
i2c_start();
i2c_write(slave_addr);
i2c_write(value1);
i2c_stop();
}

void read_I2C()
{

i2c_start();
n=i2c_write(0x11);
while(n==1)
{
i2c_start();
n=i2c_write(0x11);

}
value_re1 = i2c_read();
i2c_read(1,0);
i2c_stop();
}

void main()
{
const int8 slave_addr = 0x10;
set_tris_b(0x00);
while(1)
{
write_I2C(5,slave_addr);
delay_ms(10);
read_I2C();
output_b(value_re1);
}
}
// slave
#include <16F877A.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP

#use delay(Clock=20000000)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x10)
BYTE addr;
#INT_SSP
void i2c_isr()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state < 0x80)
{
incoming = i2c_read();
if(state == 1)
addr = incoming;

}
if(state ==0x80)
{
i2c_write(addr);

}
}

void main()
{
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
set_tris_b(0x00);
while(1)
{
output_b(addr);

}
}
[/code]
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 3:42 am     Reply with quote

Please learn to use the code button, and try this link.

http://www.ccsinfo.com/forum/viewtopic.php?t=47549&start=

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 5:50 am     Reply with quote

also...

hmm...
"simulation on protues it all fails."

PIC101.

WHO says 'Proteus' is 100% working correctly?

Your PIC code could be 100% correct in the real world and fail in teh Proteus simulation......100s of others have found that out!!!
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 8:05 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=47549

Learn it.
Live it.
Love it.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 8:10 am     Reply with quote

However the manual should really be the starting point.

For instance, what is this meant to do?:

i2c_read(1,0);

When does I2C read use two arguments?. What then are the arguments?. Does the setup you are using support this?.

Some basic study of the manual, versus the lines posted would help a lot. Then look at the I2C examples.

It is like at least taking the time to work out what a steering wheel is, and where it is in a car, _before_ trying to drive....
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