View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
can #use i2c() be used with #int_ssp for SPI? |
Posted: Fri Jun 12, 2009 12:36 pm |
|
|
Can I define a software I2C interface (using SCL=PIN_A4 and SDA=PIN_A5) port simultaneously with a hardware SPI port defined as a slave (setup_spi(SPI_SLAVE | SPI_MODE_0_0); ) and get the #INT_SSP SPI hardware interrupt with an externally provided data a clock set?
Is that sufficiently nebulous?
I have tested the #INT_SSP ISR with a standalone testbed with the port being defined as a slave SPI port. It works correctly. I'm able to supply external clocks and data into the PIC18LF2620 and the PIC ISR goes off after 8 clocks. I can correctly read the data using an spi_read().
I added a software I2C interface to control an RTC chip. The RTC chip interface works correctly (I am able to load the RTC and read date and time values back) but now the SPI ISR is not responding.
Are these functions mutually exclusive? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 12, 2009 12:44 pm |
|
|
You have a software i2c Master on pins A4 and A5. You have a
hardware SPI Slave on the hardware SSP pins.
The problem is that pin A5 is the \SS pin for the SPI slave. There's a
conflict. I suggest that you choose a different pin for your i2c SDA signal. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Fri Jun 12, 2009 1:01 pm |
|
|
Thanks for replying.
I moved the I2C pins to SCL=PIN_A3 and SDA=PIN_A4 but I get the same (non)result.
I see the I2C interaction correctly (a peridodic read of the RTC date and time is being displayed correctly) but when I send an externally provided data and clock line into the hardware SPI port (clock on PIN_C3 and data on PIN_C4), I see no SPI ISR after multiple 8-clock cycles. I have also verified the external clock and data with an o-scope. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 12, 2009 1:07 pm |
|
|
Post your #use i2c statement and your setup_spi() statements.
Post your #define statement for the SPI chip select pin. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Fri Jun 12, 2009 1:22 pm |
|
|
They are as follows:
#use i2c(MASTER,SDA=PIN_A4,SCL=PIN_A3)
setup_spi(SPI_SLAVE | SPI_MODE_0_0);
I don't have a #use spi() defined. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 12, 2009 1:25 pm |
|
|
Post your compiler version. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Fri Jun 12, 2009 1:32 pm |
|
|
V4.093
I added the following #use spi() statement but it still doesn't seem to be getting the SPI interrupt:
#use spi(SLAVE,CLK=PIN_C3,DI=PIN_C4,DO=PIN_C5,ENABLE=PIN_A5) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 12, 2009 1:43 pm |
|
|
Post a tiny little test program that shows the problem. But it must be
"copy and paste" compilable without errors. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Fri Jun 12, 2009 1:55 pm |
|
|
That will be complicated. The RTC I'm using is an M41T81. I had to write a driver routine for the function calls for it. The driver is fairly long as it has many function calls. I could probably fashion together a single program from only the pieces needed but this will take some time.
This kinda relates back to the other post I had regarding how to debug using the ICD-U64 in a 3.3VDC system.
I will try to put something together and post it... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 12, 2009 2:14 pm |
|
|
Or you could do some testing.
Do you disable GLOBAL interrupts within the RTC driver code ?
Does the RTC code contain any residual code that might affect the
hardware i2c pins ? Such as a left-over #use i2c() statement at
the top of the RTC driver file, that uses the hardware i2c pins ?
If you believe the RTC driver code is causing the problem, then
comment out the code in each RTC routine. For those routines
that return a value, just "dummy" it up, and return a constant value.
This will give the caller what it needs, without actually doing hardware
access to the RTC chip. If the hardware accesses are the problem,
this test will probably show it. The main code would start working. |
|
|
Guest
|
|
Posted: Sun Jun 14, 2009 1:45 am |
|
|
I'll take it that you have enabled the interrupt explicitly with
Code: |
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
|
I would also add the force_sw option to the #use I2C statements to make sure that the code does not attempt to do anything with the SSP module with regard to I2C support. |
|
|
|