PIC master and slave

Thread Starter

RG23

Joined Dec 6, 2010
304
I am using two pic controllers

I want to know how to use the I2C to send data from master to slave

I want to send a count value from the master PIC, the slave should read that count value and accordingly set or reset one of its port bits for example PORTA,5 depending on the count value

If anyone has an idea please let me know

Thanks
 

t06afre

Joined May 11, 2009
5,934
Good questions draw good answers. As most us in this forum are not clairvoyant. So a good start would be to post imperative information like any code and schematics you have.
 

chrisw1990

Joined Oct 22, 2011
551
this is I2C, if you use the datasheet, you need to set up the address for your i2c slave, i.e.: 01010101 therefore everytime your masters wants to communicated, you use the standard I2C functions to communicate with address 01010101.. sending your data across..?:)
make sense?
like t06afre says though, schematics etc will help, dont even know what pic models youre using!
 

Thread Starter

RG23

Joined Dec 6, 2010
304
I implemented the following subroutine which works perfectly fine when I send data from the master PIC to a digital potentiometer AD5245

But AD5245 has a specific device ID

Pot_0:
;{
call I2C_STRT////Start I2C communication subroutine
movlw 0x58 //////Device ID (address)for digital pot
movwf I2C_Value
call I2C_SEND
movlw 0x00
movwf I2C_Value
call I2C_SEND
movlw 0x79
movwf I2C_Value
call I2C_SEND/////Send data
call I2C_STP/////Stop subroutine
return
Now I want to implement something similar but use PIC16f887 as slave

The Master PIC is PIC18f67J90

If anyone has an idea please let me know

Thanks
 

chrisw1990

Joined Oct 22, 2011
551
PIC16F887 Datasheet page 187. chapter "13.4.1 Slave Mode"
like i said, you need to set the MSSP up so you can use I2C slave, 7 or 10 bit address..
then you need to give it the address so 0101010 or whatever isnt being used in your system.
then you need to communicate. as normal.
yes?
 

Thread Starter

RG23

Joined Dec 6, 2010
304
I did try setting the MSSP I2C slave, 7 or 10 bit address but it didn't work

Do i need to set it for the master PIC also?
 

chrisw1990

Joined Oct 22, 2011
551
no, you do need to set the address though?
and then write to that address from the master?
SSPADD i think is the register you need to put the address in. again check the datasheet, it has the method of communication for it:)
from the master side -
standard I2C comms, use the address of your slave, and transmit the data you want as standard
 

Thread Starter

RG23

Joined Dec 6, 2010
304
Now I know how to transfer the data from master to slave

But I am not able to read the data from the slave

For master to slave I used the following code:

Master PIC subroutine:

call I2C_STRT
movlw 0x40
movwf I2C_Value
call I2C_SEND
movlw 0x00
movwf I2C_Value
call I2C_SEND
movlw d'10'///////data to be sent to slave PIC
movwf I2C_Value
call I2C_SEND
call I2C_STP
return

I implemented the Slave PIC subroutine in the interrupt Service routine:

btfss PIR1,3
goto $
bcf PIR1,3

btfsc SSPSTAT,5
call label_data

retfie

label_data:
movf SSPBUF,0
movwf TEMP////register to store data received from master pic
return

Above code worked perfectly for master to slave

But now I am having issues in reading the data from slave to master
 

chrisw1990

Joined Oct 22, 2011
551
so to clarify, you are transmitting the data from master to slave? but you cannot read the data? try pausing the program and having a look at the SSPBUF make sure the data youve sent is actually there.. then you know 100% its being transmited and the addressing is right..
ALSO please remember to use code tags. try editing your post if you can and using them (# button at top of reply window) it makes things so much easier to understand
 

chrisw1990

Joined Oct 22, 2011
551
i know, im trying to establish whether he actually has the communication correct at the moment.. though its triggering the interrupt for reception, and it wouldnt be if it wasnt.. obviously..
 
Top