Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: AT91SAM7X512 SPI malfunctions - disabled on write to SP_TDR
PostPosted: Thu Feb 11, 2010 1:16 pm 
Offline

Joined: Wed Dec 16, 2009 8:23 pm
Posts: 9
AT91SAM7X512 SPI malfunctions - gets disabled on write to SPI_TDR.

Configurations are (Defined in the order of writing):
  1. SPI_MR (SPI Mode Register):
    • MSTR: Master mode
    • PS: Fixed Perhipheral Select
    • PCSDEC: The chip selects are directly connected to a peripheral device.
    • PCS: Peripheral Chip Select = 0111 (NPCS[3:0] = 0111)
    • DLYBCS: Delay Between Chip Selects = 0
  2. SPI_CSR[3] (SPI Chip Select Register):
    • CPOL: Clock Polarity = 0 (The inactive state value of SPCK is logic level zero.)
    • NCPHA: Clock Phase = 1 (Data is captured on the leading edge of SPCK and changed on the following edge of SPCK.)
    • CSAAT: Chip Select Active After Transfer = 0 (The Peripheral Chip Select Line rises as soon as the last transfer is achieved.)
    • BITS: Bits Per Transfer = 0000 (8 bits)
    • SCBR: Serial Clock Baud Rate = 20
    • DLYBS: Delay Before SPCK = 0
    • DLYBCT: Delay Between Consecutive Transfers = 0
  3. SPI_CR (SPI Control Register):
    • SPIEN = 1 (Enables the SPI to transfer and receive data.)

After the configurations, the code verifies that the SPI is enabled, by checking the SPIENS bit in SPI_SR (SPI Status Register).
All the communication is done with the SPI functions that were supplied by ATMEL. (source file attached)

I noticed that if I put a delay before the write to the SPI_TDR register, then the code works perfectly and the communications succeeds.
But if not, then the SPI gets disabled (as I can see by watching at the SPIENS bit in SPI_SR), which makes the while() loop (that checks the TDRE bit of the SPI_SR in the SPI_Write() function) to iterate itself indefinitely.
The amount of delay depends on the value of the SCBR register: if SCBR has a big value, then a big delay is required. A small value of SCBR requires a small delay.

Also please note that the NPCS line num. 3 is a GPIO line, and is not controlled by the SPI controller.
I'm controlling this line by myself in the code, by de/asserting the ChipSelect#3 (NPCS3) pin when needed.
The reason that I'm doing so is because that problems occurred while trying to let the SPI controller to control this pin.

Any ideas what's causing the problem?

Attachments:

Thank you!

Regards,
Dor.


Top
 Profile  
 
 Post subject: Re: AT91SAM7X512 SPI malfunctions - disabled on write to SP_TDR
PostPosted: Wed Feb 17, 2010 10:24 pm 
Offline

Joined: Wed Dec 16, 2009 8:23 pm
Posts: 9
No one experienced this before?
Maybe someone can give me an example of how to configure the SPI interface? Thank you!


Top
 Profile  
 
 Post subject: Re: AT91SAM7X512 SPI malfunctions - disabled on write to SP_TDR
PostPosted: Sat Feb 27, 2010 5:33 pm 
Offline

Joined: Thu Feb 25, 2010 5:02 pm
Posts: 88
Are you calling SPI_Read() after each SPI_Write()?

Also I believe SPIENS is only valid for Slave operation so if you are operating in master mode you probably do not want to check this bit.

See 28.6.3.1 Master Mode Block Diagram

_________________
Duane P. Fridley, IEEE CSDP
Viable Bytes, Inc.


Top
 Profile  
 
 Post subject: Re: AT91SAM7X512 SPI malfunctions - disabled on write to SP_TDR
PostPosted: Sun Feb 28, 2010 12:50 am 
Offline

Joined: Wed Dec 16, 2009 8:23 pm
Posts: 9
Sorry but I can't see the code right now and I'll be able to read it in about two weeks. But I'll try to answer:

dfridley wrote:
Are you calling SPI_Read() after each SPI_Write()?

As far as I remember - Yes.

dfridley wrote:
Also I believe SPIENS is only valid for Slave operation so if you are operating in master mode you probably do not want to check this bit.

I mistakenly believed otherwise, thanks!

Quote:
See 28.6.3.1 Master Mode Block Diagram
I'll check that out!

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to: