Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I2C (M)SSP registry configuration

Status
Not open for further replies.

revave

Member
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
 
Last edited:
Hi Reijnko,
Whynot just use the USART to communicate with the 2550 and have the interrupt set on the 2550 to USART so when the 887 sends a message(etc) the 2550 will jump straight to it and do whatever you requested...

Regards Bryan
 
Hello Bryan,

Thank you for your reply!
For communication between the two processors this seems to me an good solution.
Do I need some configuration of the UART registry?

It's the same story for reading out the DS1307 by I2C. Oshonsoft gave many examples for comunicating by I2C or UART or other projects, but I never see some configuration of the registry's (only for timers and counters).
Reading the manuals of the devices gave a lot of information about the registry's, but makes it not easier to me.

Can it be that the oshonsoft instructionset (like I2Cread... or Serout...) is handling these configurations?
 
At this moment i still have problems with I2C communication.
I cannot communicate with the RTC DS1307.

Do I need to set the PIC to Master mode?

In some examples i find the instruction TRISx.x = 1 for the SDA and CLK ports.
Is it correct that these ports must be set as an input?

In the datasheet there are some registry's for SPI and I2C like SSPCON. Do I have to configurate these registrys or is this done by the I2Cread and write command?
 
Its working now. Because of my trial and error with the registry's, port c3 and c4 cannot be used for i2c anymore. When i use other ports it works fine.
Thanks for all the reply's!
 
Status
Not open for further replies.

Latest threads

Back
Top