Hello,
I am trying to setup a communication by I2C between a PIC16F887 (master), a PIC18F2550 (slave) and a DS1307 (slave) RTC. I think i understand the instructions for I2Cread and I2Cwrite in the softwarecode, but i have to know how to configure the several (M)SSP registry's.
The 16F887 should read the time from the DS1307 (adress 0xD0) and sometimes write new time adjustments to the DS1307 (adress 0XD1). I think the 18F2550 must have a slave adress (via registry???). The 16F887 is also writing to the 18F2550. The 18F2550 must be configured as a slave with a specified adress (i.e. 0x0A).
So, i have to conifigure the 2550 and the 877, but i dont know which bits of the registry's (5 or 6, depending of type) are important for communiction (SSPSTAT and SSPCON). Is I2C communication always done by an interrupt?
I know that only the master is sending the clocksignal over the bus. So, I think I have to configure:
-is the device master or slave
-master or slave adres
Is there anything else i have to configure?
Who can put me in de right direction..
Below the softwarecode for the 16F887 to read out the DS1307
****************************************************
AllDigital
TRISC.3 = 1
TRISC.4 = 1
SSPSTAT.SMP = 1
SSPCON.SSPEN = 1
SSPCON.SSPM3 = 1
SSPCON.SSPM2 = 0
SSPCON.SSPM1 = 0
SSPCON.SSPM0 = 0
Dim time(7) As Byte
Dim index As Byte
Dim d_hi As Byte
Dim d_lo As Byte
Symbol sda = PORTC.4
Symbol scl = PORTC.3
Const adr = 0xd0
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
'Define LCD_RWREG = portd
'Define LCD_RWBIT = 2
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
Lcdinit 0
WaitMs 1000
main:
For index = 0 To 6
I2CRead sda, scl, adr, index, time(index)
time(index) = time(index) And 0x0f
d_hi = time(index) / 16
d_lo = time(index) Mod 16
If d_hi < 10 Then time(index) = d_hi
If d_lo < 10 Then time(index) = d_lo
WaitMs 20
Next index
Lcdcmdout LcdClear
Lcdout #time(0), ":", #time(1), ":", #time(2)
Lcdcmdout LcdLine2Home
Lcdout #time(3), ":", #time(4), ":", #time(5), ":", #time(5)
WaitMs 200
Goto main 'loop forever
****************************************************
Best regards,
Reijnko
I am trying to setup a communication by I2C between a PIC16F887 (master), a PIC18F2550 (slave) and a DS1307 (slave) RTC. I think i understand the instructions for I2Cread and I2Cwrite in the softwarecode, but i have to know how to configure the several (M)SSP registry's.
The 16F887 should read the time from the DS1307 (adress 0xD0) and sometimes write new time adjustments to the DS1307 (adress 0XD1). I think the 18F2550 must have a slave adress (via registry???). The 16F887 is also writing to the 18F2550. The 18F2550 must be configured as a slave with a specified adress (i.e. 0x0A).
So, i have to conifigure the 2550 and the 877, but i dont know which bits of the registry's (5 or 6, depending of type) are important for communiction (SSPSTAT and SSPCON). Is I2C communication always done by an interrupt?
I know that only the master is sending the clocksignal over the bus. So, I think I have to configure:
-is the device master or slave
-master or slave adres
Is there anything else i have to configure?
Who can put me in de right direction..
Below the softwarecode for the 16F887 to read out the DS1307
****************************************************
AllDigital
TRISC.3 = 1
TRISC.4 = 1
SSPSTAT.SMP = 1
SSPCON.SSPEN = 1
SSPCON.SSPM3 = 1
SSPCON.SSPM2 = 0
SSPCON.SSPM1 = 0
SSPCON.SSPM0 = 0
Dim time(7) As Byte
Dim index As Byte
Dim d_hi As Byte
Dim d_lo As Byte
Symbol sda = PORTC.4
Symbol scl = PORTC.3
Const adr = 0xd0
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 5
'Define LCD_RWREG = portd
'Define LCD_RWBIT = 2
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
Lcdinit 0
WaitMs 1000
main:
For index = 0 To 6
I2CRead sda, scl, adr, index, time(index)
time(index) = time(index) And 0x0f
d_hi = time(index) / 16
d_lo = time(index) Mod 16
If d_hi < 10 Then time(index) = d_hi
If d_lo < 10 Then time(index) = d_lo
WaitMs 20
Next index
Lcdcmdout LcdClear
Lcdout #time(0), ":", #time(1), ":", #time(2)
Lcdcmdout LcdLine2Home
Lcdout #time(3), ":", #time(4), ":", #time(5), ":", #time(5)
WaitMs 200
Goto main 'loop forever
****************************************************
Best regards,
Reijnko
Last edited: