Sign in

Not a member? | Forgot your Password?

Search motoroladsp

Search tips


Subscribe to motoroladsp

Search tips

Free PDF Downloads

A Quadrature Signals Tutorial: Complex, But Not Complicated

Understanding the 'Phasing Method' of Single Sideband Demodulation

Complex Digital Signal Processing in Telecommunications

Introduction to Sound Processing

C++ Tutorial

Discussion Groups

IIR Filter Design Software

See Also

Embedded SystemsFPGA

Technical discussions about Freescale (Motorola) DSPs (including the DSP56000, DSP56300, DSP56600, 56800 DSPs).

  

Post a new Thread



Is this thread worth a thumbs up?

0

SPI receive - cnnrgrdnr - Aug 5 10:43:00 2003


Hey, Does anybody have any working code that could receive SPI
signals and send them to the pc for display. I have DSP56f827,
SDK2.5, PC Master1.2. I would be very thankful if i could have a look
at it as the code i have at the minute has lots of errors when i
debug it.

Connor




_____________________________
 Free pdf download: Complex Digital Signal Processing in Telecommunications.




RE: SPI receive - Corey, Rick - Aug 5 13:08:00 2003

Hi Conner

I would appreciate anyone's comments on what I have so far.
It seems to work, but I spent so long floundering with it not
working that I have little confidence.

For what it is worth, here are some snippets from 56803 code I'm working on.

It will send or receive 9-bit data, it is a Slave, and it uses the Rx Full
IRQ for both Receive and Transmit.
If you have a more specific question, I may be able to help.

I had no success (understatement) trying to set this up to use CPHA=1
(the simpler mode where you can just ground /SS and ignore MODFEN).
Speaking from ignorance, it seemed as if the DSP SPI peripheral just could
not keep synch with the sender (which in my case was a ColdFire 5272 QSPI
peripheral).
When I went over to using /SS (CPHA=0), I got it to work.

I would love to know if anyone else has had any luck using CPHA=1 in an
interrupt-based mode.
I'm trying to use SPI as a "data bus" with higher throughput than CANbus.

Quirks:

I'm using nine-bit data so I can have special "flag words" like MSG_START,
MSG_END, MSG_ACK and PLEASE_RESEND_MSG.
Based on the errata sheet's advice, I combined my RX and Tx IRQs.
This code snippet only shows parking the received words in a plain array.
You might need a circular buffer, or something else.
I don't address sending the data to a PC: are you thinking about serial?
The SPSCR register is key: you'll have to tweak that for whatever you want,
like one must be a Master and set the baud rate.
Oh yes: I don't use the SDK. It seemed to expect me to poll the SPI port
for each character ... not what I needed.

Rick Corey

>>>>>>>>>>>>>>>>>>>> >>>>>>>
#include "DPC_56803.h"

// ******************* SPIbus #defines- see 56803.H ********************
#define SPI_ENABLE_BIT_SPE 0x0002 // SPE is bit #1 of
SPI_ControlRegister (SPSCR)
#define SPI_OVERRUN_FLAG_OVRF 0x0800 // OVRF is bit #11 of
SPI_ControlRegister (SPSCR)

// ****** for watching SPI registers in the debugger
**************************
typedef volatile struct sSpiRegisters // locate at SPI_BASE
{
UWord16 SPSCR_StatusControlReg;
UWord16 SPDSR_DataSizeReg;
UWord16 SPDRR_DataRcvReg;
UWord16 SPDTR_DataTxReg;
UWord16 SpiBase4;
UWord16 SpiBase5;
UWord16 SpiBase6;
UWord16 SpiBase7;
} DummyVarSpiRegs;
volatile struct sSpiRegisters *gpsSpiRegs=(volatile struct sSpiRegisters
*)(SPIBASE); // for watching SPI registers in debugger

UWord16 RcvdWord=0; // for debug, file-scope
#define MaxRxIndex 300
short RcvdSpi[ MaxRxIndex ];
short RxIndex=0; /***************************************************************
* FUNCTION : InitSpiBus()
* PURPOSE : Initialize SPIbus peripheral.
* This is a slave, so the clock divisor does not matter.
* RETURNS : void
* ALGORITHM :
* setup 4 pins to be used by SPI not GPIO: MOSI, MISO, SCLK & /SS.
*
* config SPI Status&Control Reg
* config data word size: SPDSR=$A for 9-bit words
* ENable SPI: SCR |= $0020 SPI_ENABLE_BIT_SPE
*
* GENERAL SPI INFO: SPI_BASE = $0F20; SPSCR=BASE
* SPDSR=SPI_BASE+1 SPDRR=DataRxReg=SPI_BASE+2 SPDTR=DataTxReg=BASE+3
* IRQ_25=SPI Receive Full (when the Rx is full, the Tx will be empty)
***************************************************************/
void InitSpiBus( void )
{
unsigned short regTmp=0;

gpsSpiRegs = (volatile struct sSpiRegisters *)SPIBASE;

// ********* setup 4 GPIO_E pins to be used by SPI: MOSI, MISO, SCLK &
/SS E4, E5, E6 & E7
// ********* set DDR (data direction) also, unecessarily
*********************************
periphBitSet( 0x00F0, (unsigned short *)(GPIO_E_PER) ); // 4 GPIO
pins: peripheral enable

periphBitSet( 0x0040, (unsigned short *)(GPIO_E_DDR) ); // set bit
#6 (MISO is OUTPUT, GPIOE6)
periphBitClear( 0x00B0, (unsigned short *)(GPIO_E_DDR) ); // clear
bits 4-5--7, inputs // ********* SPI Data Size Register
************************************
*(unsigned short *)(SPDSR) = 0x0008 ; // SPI Data Size Register==8
means word size of 9 bits

// ********* SPI Status and Control Register Section 13.9.1 DSP80x User
Manual
*(unsigned short *)(SPSCR) = 0x0028 ; // check this register field by
field to get what you want

// ********* now write a word to send to the TxDataRegiste
*(unsigned short *)(SPDTR) = 0x1FF ; // nine bit data

// ********* ENable SPI: SCR |= $0002
***********************************
periphBitSet( SPI_ENABLE_BIT_SPE, (unsigned short *)(SPSCR) ); //
enable SPI peripheral } // end of InitSpiBus() void ISR_SPI_RxTx( void )
{
RcvdWord = *(unsigned short *)(SPSCR) ; // this read, plus the next
read, clears any OVRF

// *** test if a normal OverRun occured (we clear it with these two
reads)
if (RcvdWord & SPI_OVERRUN_FLAG_OVRF )
++NumSpiOverRuns;

RcvdWord = *(unsigned short *)(SPDRR) ; // reading Rx Data Register
clears the SPRF flag

RcvdSpi[ RxIndex++ ] = RcvdWord ;
if (RxIndex >= MaxRxIndex)
RxIndex = 0; // ********** TRANSMIT ISR *************************
// check if SPTE shows TX Empty? not needed?

*(unsigned short *)(SPDTR) = RcvdWord; return ;
} // end ISR_SPI_RxTx()
-----Original Message-----
From: cnnrgrdnr [mailto:]
Sent: Tuesday, August 05, 2003 6:44 AM
To:
Subject: [motoroladsp] SPI receive
Hey, Does anybody have any working code that could receive SPI
signals and send them to the pc for display. I have DSP56f827,
SDK2.5, PC Master1.2. I would be very thankful if i could have a look
at it as the code i have at the minute has lots of errors when i
debug it.

Connor

_____________________________________
/groups.php3


Attachment (not stored)
sample DSP SPI code.doc
Type: application/msword


_____________________________
 Free pdf download: Digital Signal Processor Fundamentals and System Design.