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 CCS Technical Support

Spi master SS (slave select) bug?

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



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

Spi master SS (slave select) bug?
PostPosted: Mon Jul 30, 2007 9:20 am     Reply with quote

Hi,

Has anyone encountered this one??
I've been searching for days now why spi_write(x) some times does not give out value X. If it does not, the value is mostly '0' or sometimes some high bits disappear. I could see that on a scope It was driving me crazy.

Investigation of bad solders ect. did not solve it. Then I suspected SS or slave select, although this pin should not function under Master mode.

In my test setup this pin is free and has a piece of wire attached (scope debug pin). It was not used and still configured as an input. So it can pickup 50/60Hz hum.

Then I made this pin an output_low -> problem gone! So my conclusion is that the hum somehow interferes in the SPI cicuitry

Has anyone encountered this issue? Maybe my chip is bad.....

Regards,
Edwin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 12:07 pm     Reply with quote

1. Post your PIC.
2. Post your compiler version.
3. Post the device that the PIC is talking to.
4. Post the list of connections between master and slave.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 12:31 pm     Reply with quote

I don't think it is a software bug.

The pic is a PIC18LF4620. The problem exists when communicating to a flash mem. SST25VF016 (16Mbit).
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 12:45 pm     Reply with quote

Quote:
I don't think it is a software bug.
Writing this line has taken you more time than it would have to mention your compiler version.

Please answer all PCM's questions. You are the one who wants to be helped, so put some effort in it. Right now we don't have enough to go on.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 1:27 pm     Reply with quote

My apologies, your right.

The code is a bit big to post. So I'm already busy simplifying my code to the lines that do the trick. And also testing it on a 18LF2685. I'll post it asap. I'll test the same code tomorrow on the other 18LF4620.

Compiler version PCWH 4.047
ICD-U40 v2.79

Regards,
Edwin.
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 2:21 pm     Reply with quote

I can reproduce the same on a pic18LF2685 running on 5v, internal oscillator on 4 Mhz. You do need a digital scope to see it. Attach Sclk and Do. Trigger on Sclk. Watch the output data being distorted when you touch PIN_A5 with your finger. The latter doens't happen when Pin-A5 has been made an output.

I'm thinking of applying an asynchronous TTL signal to this PIN_A5. Touching it with your finger might be a little overkill although a piece of wire did the trick in my application.

Code:

#include <18F2685.h>
#FUSES NOWDT,INTRC_IO, NOPUT, NOLVP, Nobrownout
#device ICD=TRUE

#use standard_io(A)
#use standard_io(B)
#use standard_io(C)

#use delay(clock=4000000)

void main()
{
  long cnt;
  short t,j;
  int8 i,k,l;
  char c;
 
  setup_oscillator(OSC_4MHZ | OSC_INTRC );
  setup_spi(SPI_MASTER | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4);       
 
  input(PIN_A5);           // WARNING! CAUSING SDO PROBLEMS IF HUM IS PICKED UP !!
  //output_low(PIN_A5);    // do this and problems are gone.
  while(true) {
    delay_ms(500);
    spi_write(0x06);   
    spi_write(0x60);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 3:12 pm     Reply with quote

I looked at the code in the .LST file for your version, and I didn't see
anything wrong. The start-up code is setting the analog pins to be all
digital i/o.

Here is another person with your problem, on the Microchip forum.
http://forum.microchip.com/tm.aspx?m=254485&mpage=1

It may be a hardware bug.
If you have to leave it as an input pin, then put a pull-down resistor on it.

I didn't see an errata on your PIC for this problem, but there might be
one on another PIC. You could look through all the erratas that mention
certain keywords, in an attempt to find one that may show the problem.
Here's a Google search string that shows a lot of the erratas:
Quote:
site:microchip.com "slave select" errata SPI Master SDO
Torello



Joined: 29 Sep 2006
Posts: 120

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 3:28 pm     Reply with quote

Thanks for the tips.

I did hook up an async TTL signal and indeed it screws up the output of the SPI. Maybe I'll report it to microchip. For now I don't need this pin, so ill output it low.

Pffft.... I'm happy to have found this bug; took me days! Very Happy

Regards,
Edwin
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 4:37 pm     Reply with quote

Just as a general design note: never have open pins configured as input for this will cause a high power consumption.
Normally CMOS circuits don't use current, except when switching. Now it happens that open inputs tend to float at half the power supply voltage and start oscillating at this voltage. The high oscillating frequency could cause a current draw of tens of mA.

Several discussions can be found on the internet about what is the best thing to do with unused i/o-pins. It seems like there is no 'best solution' for all situations, but leaving pins open and configured as input is always considered bad.
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