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 |
|
SPI receive
Started by ●August 5, 2003
Reply by ●August 5, 20032003-08-05
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; SPSCRSE * SPDSR=SPI_BASE+1 SPDRRaRxReg=SPI_BASE+2 SPDTRaTxRegSE+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 _____________________________________ Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group. _____________________________________ About this discussion group: To Join: To Post: To Leave: Archives: http://www.yahoogroups.com/group/motoroladsp More Groups: http://www.dsprelated.com/groups.php3 ">http://docs.yahoo.com/info/terms/ | |||
|