Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with SPI and SS pin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 271
Location: McMinnville, OR

usa.gif
PostPosted: Tue Jul 26, 2011 4:09 pm    Post subject: Problem with SPI and SS pin Reply with quote

I'm seeing a problem with the SPI outputs when the SS pin is not configured.

If SS is not configured as output SCK and MOSI have no output signals.

I don't know if this is a hardware problem, software problem or maybe it is suppose to be that way.

Code:
'Test code to demonstrate problem with hardware spi output.

'Tested with version 2.0.7.0 and 1.12.0.0

'SPI works fine if portC.0 (SS) is configure as output.
'If portC.0 is not configured MOSI and SCK are dead even though Noss=1.

'A scope is needed to see this problem. See pins 17 & 19.


$regfile = "m328pdef.dat"
$crystal = 8000000

$hwstack = 60
$swstack = 60
$framesize = 60

dim Spi_h as byte
dim Spi_l as byte

'config Portb.2 = output '*** required for spi to work ***

cs Alias Portc.0
Config cs = Output
Set cs

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , _
Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 1
Spiinit

do
   Reset cs
   waitus 4
   'send hi byte.
   Spi_h = Spimove(&hAA)
   'send lo byte.
   Spi_l = Spimove(&hAA)
   'deselect chip.
   Set cs
loop
 
Back to top
View user's profile
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Tue Jul 26, 2011 4:54 pm    Post subject: Reply with quote

That is as designed for the AVR. This is from the AVR chip document (pdf)... "When configured as a Master, the SPI interface has no automatic control of the SS line. This must be handled by user software before communication can start."
Back to top
View user's profile Yahoo Messenger
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 271
Location: McMinnville, OR

usa.gif
PostPosted: Tue Jul 26, 2011 5:12 pm    Post subject: Reply with quote

DToolan, Thanks for the reply.

I use another pin for chip select and that works. The problem is if I need pin 16 (SS) for input SPI dies. Shouldn't I be able to do that? Another words not use the SS pin for SPI at all?

EDIT: Ok I read through the data sheet again and the bascom help. It is explained so now I get it. Not exactly intuitive through.

Quote:
If SS is configured as an output, the pin is a general output pin which does not affect the SPI
system. Typically, the pin will be driving the SS pin of the SPI Slave.

If SS is configured as an input, it must be held high to ensure Master SPI operation. If the SS pin
is driven low by peripheral circuitry when the SPI is configured as a Master with the SS pin
defined as an input, the SPI system interprets this as another master selecting the SPI as a
slave and starting to send data to it.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum