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

"Ghost" driving SDO pin in SPI mode

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



Joined: 01 Nov 2005
Posts: 10

View user's profile Send private message

"Ghost" driving SDO pin in SPI mode
PostPosted: Fri Aug 03, 2007 10:10 am     Reply with quote

I am using a PIC18F2420 as an SPI master to drive a MAX532 dual 12-bit DAC. This has been working 99% of the time, but I am occasionally seeing what seems like a "ghost" driving my SDO pin in SPI mode. There is nothing else sharing this pin in software or hardware. I initialize the TRIS, and that's it.

What I am seeing on the scope is the SDO pin change state between transmitted bytes, and also sometimes even between clock pulses. The result is glitches in the analog output. What I'm trying to drive onto the SPI bus is not the same as what appears on the bus. A scope trace can be found at

http://www.4004.com/spi-ghost-scope-trace.bmp

Channel 2 is the SCK and Channel 3 is SDO. Notice how it changes before the burst of clock pulses and stays high afterwards.
The scope was triggered when the analog signal went out-of-bounds. Here is another scope trace with the SDO changing between clock pulses.

http://www.4004.com/between-ck-pulses-scope-trace.bmp

I added the 1us delays during debugging because the Silicon Errata suggested that there might be some hardware bugs in the MSSP module.

Anyone seen anything like this? This is very strange.

Code:

void initialize_peripherals (void)
{
  output_low(SCK_PIN);    //   SCK_PIN output (driven by SPI module)
  output_low(SDO_PIN);    //   SDO_PIN output (driven by SPI module)
  output_float(SDI_PIN);  //   SDI_PIN input (monitored by SPI module)
  ...
  setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16)

void spi_12x2_out (...)
{
  ...
  output_low(CS_PIN);
  delay_us(1);
  spi_write(byte1);
  delay_us(1);
  spi_write(byte2);
  delay_us(1);
  spi_write(byte3);
  output_high(CS_PIN);
}
Ttelmah
Guest







PostPosted: Fri Aug 03, 2007 10:18 am     Reply with quote

You say you are setting TRIS. Are you selecting 'fast_io' mode?. If not, the compiler will still control TRIS. How are you generating the SPI data?. Is this using the chip's hardware, or one of the software implementations (as in many of the example files, or using the new ability to do this in V4)?.

Best Wishes
mcpublic



Joined: 01 Nov 2005
Posts: 10

View user's profile Send private message

Re: "Ghost" driving SDO pin in SPI mode
PostPosted: Fri Aug 03, 2007 11:20 am     Reply with quote

Thanks for the suggestion. This firmware doesn't #use fast_mode. But I wouldn't expect this to be an issue as I don't do any explicit I/O on the SDO pin. I just let the MSSP module control it.

My next experiments I'm thinking of are (a) to add a pull-down resistor to the SDO line, and (b) lift the SDO pin. The pull-down will tell me if the TRIS is being messed with, and the lifted pin will let me see if anyone else is driving the bus (it could only be the DAC input pin, but maybe there are ESD protection diodes that are doing something funky.
mcpublic



Joined: 01 Nov 2005
Posts: 10

View user's profile Send private message

Re: "Ghost" driving SDO pin in SPI mode
PostPosted: Fri Aug 03, 2007 11:33 am     Reply with quote

P.S. I am using the PIC18F2420's MSSP hardware to generate SPI signals.
Ttelmah
Guest







PostPosted: Fri Aug 03, 2007 12:40 pm     Reply with quote

OK.
I'd suggest making a bit define of the SPI buffer empty status bit. Write the data, then wait till this goes true, _before_ doing your extra delay. I have a nasty feeling you are being hit by a MSSP hardware problem (there are a hell of a lot on some of these chips...), which the internal functions may be not helping with...

Best Wishes
mcpublic



Joined: 01 Nov 2005
Posts: 10

View user's profile Send private message

PostPosted: Fri Aug 03, 2007 2:04 pm     Reply with quote

That's a very good suggestion. And I agree with your diagnosis,
as I've pretty much confirmed that it is either a hardware bug
or a bug inside CCS C "PCH" SPI library (I suppose it may
have gotten fixed/worked-around after version 3.236;
I'll upgrade if it definitely did)

Here's what I did to isolate the problem:

First I used spi_read() to verify if what I was passing to
spi_write() was actually getting written onto the bus.
It wasn't.
Then I implemented "bit-banged" SPI in software.
No more glitches. And a loss of only half the SPI bandwidth.
(1.25MHz instead of 2.5MHz using SPI_CLK_DIV_16)
I never had to lift a soldering iron or cut any 30GA wire, whew!
scorp



Joined: 01 Apr 2008
Posts: 1

View user's profile Send private message

PostPosted: Tue Apr 01, 2008 7:25 am     Reply with quote

I had nearly the same problem using PIC18LF4620 and PIC18LF2420. On PICLF2420 i just decided to use my software SPI functions and problem had gone. Recently, on PIC18LF4620 I decided to dig into the problem and found that hardware SPI works unpredictable if PIC has floating pins(unconnected and programmed as inputs). Reprogramming unused I/Os as output solved issue. I always used fast_io.
Can anybody prove or disprove it, please?
Ttelmah
Guest







PostPosted: Tue Apr 01, 2008 8:33 am     Reply with quote

Having floating input pins is 'bad practice' anyway. Will result in increased power consumption, and more risk of ESD problems. Rules generally are, that unused pins should always either be programmed as outputs, or tied to a rail with a resistor (this is 'better', than shorting directly to a rail, since it prevents damage, if you latter accidentally drive the pin, and on a couple of older CMOS families, avoids a potential 'latch up' problem).
Now, on the PIC in general, there are significant oddities with a number of pins, if they float, and the protection diodes come into play. In general, some features that are turned off, can start to actually work, if a pin goes outside the supply rails. In particular, for the SPI, I'd not be at all surprised if the slave select line, could actually deselect the input, even if disabled, if this happens...

Best Wishes
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