![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
micro2 Guest
|
i2c and spi |
Posted: Fri Feb 17, 2006 10:43 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Feb 17, 2006 11:03 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Feb 17, 2006 11:08 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
Posted: Fri Feb 17, 2006 11:36 am |
|
|
for I2C mode:
movlw 0x28
movwf sspcon1
for SPI mode:
movlw 0x21
movwf sspcon1
is correctly?
it can work ?
thanks |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Feb 17, 2006 11:39 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
Posted: Fri Feb 17, 2006 1:47 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Feb 18, 2006 6:10 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sat Feb 18, 2006 6:16 am |
|
|
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.
??
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
Posted: Sat Feb 18, 2006 6:33 am |
|
|
the precedent author 'Guest? is micro2
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Feb 19, 2006 5:12 am |
|
|
'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 |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
Posted: Sun Feb 19, 2006 12:22 pm |
|
|
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....
Bye |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 19, 2006 4:11 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
micro2 Guest
|
|
Posted: Mon Feb 20, 2006 7:17 am |
|
|
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] |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|