Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
34
Добавлен:
27.04.2015
Размер:
1.98 Mб
Скачать

Configuring Port C for SPI Functionality

7.5 Configuring Port C for SPI Functionality

The PCC register is used to individually configure each pin as either an SPI pin or a GPIO pin. When the SPI is used in Slave mode, all four SPI pins must be programmed as SPI pins in the PCC register. When in Master mode, the SCK, MISO, and MOSI pins are configured as SPI pins, and the SS pin is optionally configured as an SPI pin if mode-fault detection is desired. Otherwise, SS can be configured as a GPIO pin in the PCC register. This is summarized in Table 7-4.

Table 7-4. PCC Register Programming for the SS Pin

 

CC Bit1

 

 

 

 

 

Mode

Functionality of the SS Pin

 

 

 

 

 

 

Slave

0

Not allowed

 

 

 

Slave

1

Used as

 

pin

SS

 

 

 

Master

0

Used as GPIO pin

 

 

 

Master

1

Used for mode-fault detection

 

 

 

 

 

 

 

1.For SPI0, use PCC[3]. For SPI1, use PCC[7].

When the PCC register bit is set for an SPI pin, it is not necessary to program the corresponding PCDDR bit. The SPI peripheral ensures the correct direction of this pin. Programming the PCDDR is necessary only when a pin is programmed as a GPIO pin.

In applications requiring minimum power consumption, the SPI module can be disabled by clearing the SPE bit in SPCR. This also shuts off the Phi clock signal as it enters the block.

Stop mode automatically disables the SPI peripheral and any external clocks for devices configured in Slave mode. The internal Phi clock is stopped in stop mode. If a device is in the middle of a transfer when it enters stop mode, all internal state machines are reset so that, upon exiting stop mode, the device waits for a new transfer to be initiated.

In wait mode, the SPI peripheral continues operation and can complete transfers in progress. If the SPI interrupt is enabled in the SPCR, IPR, and SR, the SPI peripheral can generate an interrupt request in wait mode that brings the DSP56824 out of wait mode.

7.6 Programming Examples

Example 7-1 through Example 7-3 on page 7-17 show how to configure one SPI port as a master, how to configure one as a slave, and how to send data from master to slave.

7.6.1 Configuring an SPI Port as Master

Example 7-1 shows how to configure an SPI port as a master.

Serial Peripheral Interface

7-13

; External Program memory has 0 wait states. ; External data memory has 0 wait states.
; Port A pins are tri-stated when no ; external access occurs.
$0000,X:BCR

Serial Peripheral Interface

Example 7-1. Configuring an SPI Port as Master

;******************************************

;* SPI master

 

 

*

;* for serial peripheral interface (SPI)*

;* of DSP56824 chip

 

 

*

;******************************************

START

 

EQU

$0040

; Start of program

BCR

 

EQU

$FFF9

; Bus Control Register

IPR

 

EQU

$FFFB

; Interrupt Priority Register

PCC

 

EQU

$FFED

; Port C Control Register

PCDDR

 

EQU

$FFEE

; Port C Data Direction Register

PCR0

 

EQU

$FFF2

; PLL Control Register 0

PCR1

 

EQU

$FFF3

; PLL Control Register 1

SPCR0

 

EQU

$FFE2

; SPI0 Control Register

SPDR0

 

EQU

$FFE0

; SPI0 Data Register

SPSR0

 

EQU

$FFE1

; SPI0 Status Register

;**************

 

 

 

;* Vector setup*

 

 

 

;**************

 

 

 

 

ORG

P:$0000

 

; Cold Boot

 

JMP

START

 

; also Hardware RESET vector (Mode 0, 1, 3)

 

ORG

P:$E000

 

; Warm Boot

 

JMP

START

 

; Hardware RESET vector (Mode 2)

;

ORG

P:$0028

 

;

;

JSR

[unused]

; SPI1 Serial System vector

 

ORG

P:START

 

; Start of program

;***************** ;* General setup * ;***************** MOVEP

7-14

DSP56824 User’s Manual

 

Programming Examples

Example 7-1. Configuring an SPI Port as Master (Continued)

;********************************************************* ;* Phi Clock included for serial bit clock of SPI Master * ;*********************************************************

MOVEP

#$0180,X:PCR1

;Configure:

 

 

;(PLLE) PLL disabled (bypassed)

 

 

; -- Oscillator supplies Phi clock.

 

 

;(PLLD) PLL Power Down disabled (PLL active).

 

 

; -- PLL block active for PLL to attain lock.

 

 

;(LPST) Low Power Stop disabled.

 

 

;(PS[2:0]) Prescaler Clock disabled.

 

 

;(CS[1:0]) Clockout pin sends Phi clock.

MOVEP

#$0260,X:PCR0

; Set Feedback Divider to 1/20

 

 

; ...

 

 

; insert delay here: wait for PLL lock

 

 

; as specified in data sheet

 

 

; ...

BFSET

#$4000,X:PCR1

; Enable PLL for Phi clock.

;********************

 

;* SPI Master setup *

 

;********************

 

BFCLR

#$0040,X:SPCR0

; (SPE) SPI disabled

MOVEP

#$0116,X:SPCR0

; Configure:

 

 

; (SPR[2:0]) SPI Clock Rate Select at /64.

 

 

; (SPIE) SPI Interrupt disabled.

 

 

; (WOM) Wired-OR mode disabled:

 

 

; - push-pull drivers.

 

 

; (MST) Master mode selected.

 

 

; (CPL) serial Clock Polarity:

 

 

; - SCK pin idles as logic low.

 

 

; (CPH) Clock Phase protocol:

 

 

; - ~SS line can be tied low if only 1 slave.

BFSET

#$0007,X:PCC

; Configure:

 

 

; MISO0, MOSI0, SCK0 for SPI master,

 

 

; ~SS0 as PC3 for GPIO.

 

 

; Other pins remain as previously set.

 

 

; (reset default is GPIO).

BFSET

#$0008,X:PCDDR

; Configure GPIO pin PC3 as output

BFCLR

#$2000,X:IPR

; Disable SPI0 interrupts

completeness).

; (unnecessary but mentioned for

 

BFSET

#$0040,X:SPCR0

; (SPE) SPI Enabled.

;****************

 

;* Main routine *

 

;****************

; ...

 

 

TEST

 

; Test Loop

BRA

TEST

; ...

 

 

 

 

Serial Peripheral Interface

7-15

Соседние файлы в папке DSP568xx