|
|
View previous topic :: View next topic |
Author |
Message |
mike cambridge Guest
|
spi and interupts? |
Posted: Fri Aug 31, 2007 3:06 am |
|
|
I am having some problems with SPI on a project that uses an extenal interupt onto CCP1. If I stop the interupts (remove the external signal) some of the problems, but not all, go away!
I have started to wonder about interupts and SPI, in general should I disable interupts when calling the SPI routines or is this done in the Pic hardware or the C driver code? Or dont you need to, I realise that the data is all tramsnitted on the clock, I guess if the clock stops (while servicing an interupt) then everything waits until the clock continues.
thanks
mike (Cambridge UK). |
|
|
Ttelmah Guest
|
|
Posted: Fri Aug 31, 2007 3:52 am |
|
|
The clock is not affected by the interrupts at all.
The SPI, will send fine, with all sorts of interrupts running.
However, this is only true of _hardware_ SPI. If you are using the V4 'software' library, then the transmission will stop completely during the interrupt.
Even with hardware, where you may see problems, are if the slave device, has a tight timing requirement, and (for instance), treats a transaction as failed/complete, if the subsequent bytes do not arrive in a specific interval. In this case, the long 'pause' involved between bytes, while the chip goes off and handles interrupts, may introduce problems.
The fact that you still have problems without the interrupts, suggests that there is something wrong, which the interrupts are only making worse. You need to find what is happening.
What is the slave device?.
What SPI setup are you using?.
What processor is involved?.
How are the connections made (length, capacitance etc. etc.)?.
Best Wishes |
|
|
mike cambridge Guest
|
spi and interupts? |
Posted: Wed Sep 05, 2007 4:19 am |
|
|
Thanks for the reply
I am using a 18f4685, V4.053, hardware routines.
background: I am using the PIC to monitor a shaft rotation (zero pulse and 180 pulses per rev). I feed the zero into the ccp1 input and generate an interupt every rotation, I count the pulses to get shaft rotary position by feeding it into RA4/t0ck1 and thus can work out the shaft pos'n
I am driving a spi2620 D/A chip from the SPI bus.
The problem is that the D/A value changes (randomly) when there is an pulse input into the RA4 input. BTW Have disabled interupts and this has no effect.
Ground the Ra4 pin and problem stops, generate noise on pin (by holding it) and problem gets much worse!
Looked at the SPI bus signal with a scope and the data bytes are changing value when they shouldnt, something is corrupting the data being sent out.
Looking at the SPI hardware in the chip (data sheet) and seems that RA4 is used if in SPI slave mode (it goes into the SSPSR reg clock (via AND gate controlled by slave mode). Checked the SPI control reg (by looking at the values after they have been set, using ICD2) and
SSPCON1 = 00100000 which I think (not sure of anything now...) is SPI master mode and SPI master mode clock div 4.
So the input onto RA4 should not do anything but does!
So I think the problem is a hardware issue and am thinking of a work around, unless anyone has any other ideas (I have been struggling with this problems for a few days and could well have missed something simple).
regards
mike
(note: offline from thursday until 10 Sept, on Classic Triumph car tour of 10 european counties....) |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 05, 2007 4:41 am |
|
|
Have fun in the Triumph. What model?.
One thought niggles into my mind. Some of these chips, have a 'clock monitor' circuit, which is designed to switch the processor to an internal RC oscillator, if the 'main' clock sources fail. If the chip is in 'dual speed' mode, Timer1, will be flagged as the secondary oscillator. If this was hapening, different clock patterns on th T1 input, could trigger a clock speed change...
Now, also tied with this, there are cases (as with MCLR), where these internal circuits, have effect, even when they are turned off, when a signal exceeds the Vss to Vdd range, and relies on the clamp diodes. Try clamping the input signal, externally to the PIC, possibly with something like a series resistor, 4v7 zener, to ensure it cannot go above 5v (assuming you are operating off a 5v supply). Make sure that oscillator switching is disabled (IESO, and FCMEN off).
Best Wishes |
|
|
mike cambridge Guest
|
spi and interupts? |
Posted: Wed Sep 05, 2007 6:53 am |
|
|
OT: Its a 1968 Triumph Herald Convertible, will be driving it with my daughter! The tour is run by Club Triumph
club dot triumph dot org dot uk
Thanks for the suggestions will check some of them out but in the meantime will try using one of the other timer to count the rotary pulses.
regards
mike |
|
|
|
|
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
|