Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 19, 2025, 11:20:34 23:20


Login with username, password and session length


Pages: [1]
Print
Author Topic: i2c  (Read 6470 times)
0 Members and 1 Guest are viewing this topic.
mrnitigon
Guest
i2c
« on: January 08, 2008, 05:05:16 05:05 »

can i use pic basic to program communication 2 pic
Logged
creatv
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 6
-Receive: 1


« Reply #1 on: January 08, 2008, 08:19:39 20:19 »

Yes, you can use picbasic proton for comunicate with 2 pic.
You can use the I2C bus or RS232 standard
Logged
mrnitigon
Guest
« Reply #2 on: January 09, 2008, 10:17:01 10:17 »

thank but i dont know how can i program slave address
Logged
Roshan
Newbie
*
Offline Offline

Posts: 17

Thank You
-Given: 5
-Receive: 2


« Reply #3 on: January 09, 2008, 12:55:01 12:55 »

check sspadd,sspcon & sspstat register. Read carefully & you can use pic as slave devices.

Roshan
Logged
creatv
Newbie
*
Offline Offline

Posts: 18

Thank You
-Given: 6
-Receive: 1


« Reply #4 on: January 09, 2008, 06:44:43 18:44 »

Hi, you can use this program for slave I2C




' PicBasic Plus I2C slave program - PIC16F877

        Device 16F877
        XTAL = 4
       
' Alias pins
      Symbol SCL = PORTC.3                  ' I2C clock input
      Symbol SDA = PORTC.4                  ' I2C data input

' Define used register flags
      Symbol SSPIF   PIR1.3             ' SSP (I2C) interrupt flag
      Symbol BF      SSPSTAT.0          ' SSP (I2C) Buffer Full
      Symbol R_W      SSPSTAT.2          ' SSP (I2C) Read/Write
      Symbol D_A      SSPSTAT.5          ' SSP (I2C) Data/Address
      Symbol CKP      SSPCON.4           ' SSP (I2C) SCK Release Control
      Symbol SSPEN   SSPCON.5           ' SSP (I2C) Enable
      Symbol SSPOV   SSPCON.6           ' SSP (I2C) Receive Overflow Indicator
      Symbol WCOL      SSPCON.7           ' SSP (I2C) Write Collision Detect

' Allocate RAM
      Dim datain  as     Byte              ' Data in
      Dim dataout as     Byte              ' Data out
       
'------------------------------------------------------------------------------------
        Goto main                       ' Jump over the subroutines
'------------------------------------------------------------------------------------

' I2C slave subroutine
i2cslave:
        SSPIF = 0                        ' Clear interrupt flag
        If R_W = 1 Then i2Crd            ' Read data from bus
        If BF = 0 Then Return              ' Nothing in buffer so exit
        If D_A = 1 Then i2cwr            ' Data for bus (not address)
        If SSPBUF != 2 Then Return           ' Clear the address from the buffer
        Return
'------------------------------------------------------------------------------------
' I2C write data to bus
i2cwr:   datain = SSPBUF                   ' Put data into datain
        Return
'------------------------------------------------------------------------------------
' I2C read data from bus
i2crd:  SSPBUF = datain                   ' Get data from datain
        CKP = 1                          ' Release SCL line
      Return
'------------------------------------------------------------------------------------
' Main program loop
Main:       
' Initialise ports and directions
        ADCON1 = 7                       ' All PORTA, PORTE pins to digital

' Initialise I2C slave mode
        SSPADD = 2                       ' Make our address 2
        SSPCON2 = 0                      ' General call address disabled
        SSPCON = $36                     ' Set to I2C slave with 7-bit address
       
Again:  If SSPIF = 1 Then Gosub i2cslave   ' Check for I2C interrupt

' Clear any I2C collisions or errors
        SSPOV = 0
        WCOL = 0
        Goto Again                       ' Do it all forever
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 85


« Reply #5 on: January 09, 2008, 11:33:08 23:33 »

Nice code CREATV
It works for me.

I interconnected two 16F877 PICS per SDA and SCL.

heres the testing Code.

Code:
' PicBasic Plus I2C Master program - PIC16F877

        Device 16F877
        XTAL = 4
   
' Alias pins
      Symbol SCL = PORTC.3                  ' I2C clock line
      Symbol SDA = PORTC.4                  ' I2C data line

' Allocate RAM
      Dim dataout As     Byte              ' Data out
       

'------------------------------------------------------------------------------------
' Main program loop
Main:       
' Initialise ports and directions
ADCON1 = 7                       ' All PORTA, PORTE pins to digital
dataout = 0                      ' Will use this byte as signal

Again:
        Toggle PORTA.0                         ' Just to show PIC is Runing
        I2Cout  SDA,SCL,  2 , [ dataout ]      ' Send data
        DelayMS 10                             ' I always use this delay after I2Cwrite
        DelayMS 100                            ' Pause for watching response on second pic
        dataout = dataout + 1                  ' increment value of
        GoTo Again                       ' Do it all forever
       

On the Slave side i did a litlle variation , to see the data that was incoming ,...

Code:
' I2C write data to bus
i2cwr:   datain = SSPBUF                   ' Put data into datain
        SerOut PORTC.6,84,[ "In: ",DEC4 datain,13]                ' added line
        Return
'------------------------------------------------------------------------------------

Simulate it in Proteus .
All Ok.

Greetings

Logged
mrnitigon
Guest
« Reply #6 on: January 10, 2008, 02:14:33 02:14 »

 Cheesy thank for all post it is best for me
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC