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 support@ccsinfo.com

i2c and spi

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







i2c and spi
PostPosted: Fri Feb 17, 2006 10:43 am     Reply with quote

Hi,
I have a Board of the Modtronix with 24lc256 and ds1307 in I2C mode and lcd connect with a connector in SPI mode (Chip select with PIN_B3).
The LCD works correctly with:
Code:
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16);

but not the eeprom and the rtc in I2C mode:
Code:
#use i2c(Master,sda=PIN_C4,scl=PIN_C3,force_hw);


Why?
(Pic = 18f458 xtal = 20MHz)

Thanks
Ttelmah
Guest







PostPosted: Fri Feb 17, 2006 11:03 am     Reply with quote

Because you cannot use the same hardware for two jobs.
There is only one MSSP module in your PIC. This can be programmed to either provide I2C functionality, or SPI functionality. You have programmed it for SPI, so it cannot also provide I2C.

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 17, 2006 11:08 am     Reply with quote

I just wonder if a tri-state latch of some sort could be put in between with an
enable that will let you select I2C or SPI?
micro2
Guest







PostPosted: Fri Feb 17, 2006 11:36 am     Reply with quote

for I2C mode:
movlw 0x28
movwf sspcon1

for SPI mode:
movlw 0x21
movwf sspcon1

is correctly?
it can work ?

thanks
Ttelmah
Guest







PostPosted: Fri Feb 17, 2006 11:39 am     Reply with quote

Yes.
With some care, it can be done. You'd need to write the code, so that it reprograms the device registers, then goes to the code for that device. Possibly the simplest way to switch the signals, would be to use a 4066, and have two gates of this in the two I2C lines, then have the pullup resistors, and the I2C devices. To talk to the I2C devices, deselect the CS line on the SPI device, have the I2C #use statement, turn on the gates in the 4066, and talk as normal. To talk to the SPI device, deselect the 4066, have the SPI setup call, and then talk to this. If you don't isolate the lines to the I2C devices, there is a good chance of accidentally sending a start condition amongst the SPI data traffic...

Best Wishes
micro2
Guest







PostPosted: Fri Feb 17, 2006 1:47 pm     Reply with quote

I do not think is necessary the use of the analog switch 4066 and I cannot modify the hardware.
for now, i am testing only the 24lc256 and strangely only the first byte is written correctly, when I read, the following byte are all 0xff.
Why?

Tanks
micro2
Guest







PostPosted: Sat Feb 18, 2006 5:51 am     Reply with quote

Now work, I have used the following code http://www.ccsinfo.com/forum/viewtopic.php?t=22587&highlight=m24256 by pirev.
the problem is now for the ds1307, there is a good code?
The code on the forum not working seems, the battery is connected but the time read is locked to 45/85/85.

Thanks
Ttelmah
Guest







PostPosted: Sat Feb 18, 2006 6:10 am     Reply with quote

I think you are still 'running a risk', that data corruption will occur at random.
On the 1307, try it on it's own. Also, you say you have a battery connected. What voltage?. There is a problem, that if the battery voltage is too high, it disables normal operation!.The switchover 'point', is when Vcc=1.25*Vbatt. If you use a 3.5v Lithium Thionyl Chloride cell, and it is new, you can find that there is a problem getting the chip to operate. The switchover 'point', is itself nominal, rather than exact, and I have seen units fail to switch with supply rails of 4.9v, in this situation...

Best Wishes
Guest








PostPosted: Sat Feb 18, 2006 6:16 am     Reply with quote

why 'running a risk'?
The SPI is disabled when i work in I2C mode and CS_LCD (LCD enable) is also disabled.
The battery voltage is exactly 3.00V.
?? Crying or Very sad

Thanks
micro2
Guest







PostPosted: Sat Feb 18, 2006 6:33 am     Reply with quote

the precedent author 'Guest? is micro2 Embarassed

Thanks
micro2
Guest







PostPosted: Sun Feb 19, 2006 4:48 am     Reply with quote

Help me Crying or Very sad
the 1307 not work ....., the hardware and the voltage battery is ok!!
Why?
there is some problem in the code?
http://www.ccsinfo.com/forum/viewtopic.php?t=23255&highlight=ds1307
The time is fix to 45.85.85

Bye[/code]
Ttelmah
Guest







PostPosted: Sun Feb 19, 2006 5:12 am     Reply with quote

'Running a risk', because the waveform combinations you can get on the pins, when running SPI, could generate an I2C 'start'. If an I2C chip sees this, happens to see a pattern that it recognises, and decides to pull the data low (remember I2C allows this), you would get two chips fighting to drive the one line, and data corruption.
You should really go through every possible SPI data pattern, and verify that none of them correspond to I2C patterns. A lot of work...
Your problem is probably bus speed. Add 'slow=100000' to your I2C setup. The DS1307, only supports the 100K I2C rate.

Best Wishes
micro2
Guest







PostPosted: Sun Feb 19, 2006 12:22 pm     Reply with quote

ok, some, in a few combinations it can be there a bus collision, but only when i write/read on the LCD and for me this can not be a problem.
The setup speed is 100kHz but the ds1307 not work.... Crying or Very sad

Bye
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 19, 2006 4:11 pm     Reply with quote

micro2 wrote:
the 1307 not work ....., the hardware and the voltage battery is ok!!
Why?
there is some problem in the code?
http://www.ccsinfo.com/forum/viewtopic.php?t=23255&highlight=ds1307
The time is fix to 45.85.85[/code]
Seems to me like you do have a hardware problem, even though you deny it. Have a look at this thread, here they received the same data sequence you get and this turned out to be a problem with the battery pin connected to the +5V.
micro2
Guest







PostPosted: Mon Feb 20, 2006 7:17 am     Reply with quote

I do not think ckielstra, the board is manufactured by modtronix
http://www.modtronix.com/products/sbc44b/sbc44br2.pdf]
and it is perfectly(I have two Board).
I have only externally added the lithium battery (pin3-4 'JP1', 3.00V) but not work.

Bye[/code]
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