SPIRead Question

HI Guys,

I have a strange one. I am using a RCM6700 and using SPI port D. I have found that the very first time I call the function SPIRead it finishes after only issuing two of the 16 clock cycles. All subsequent SPIReads are fine. Its as if the SPIRead is not initialized correctly the first time. The obvious solution is to run a dummy SPIRead when th eprogram starts up but I was wondering if anyone else has come across this?

This is how I initialized Port D and I call SPIInit() prior to the first read

/************* SPI Setup ********************************************/
#define SPI_MASTER
#define SPI_SER_D
#define SPI_CLK_DIVISOR 100
#define CLOCK_PORT D
#define SPI_RX_PORT SPI_RX_PC                                    // Use Parallel Port C for SPI port D
#define CLOCK_BIT 0
#define SPI_CLOCK_MODE 0

Thanks

OK, this is an interesting one.

Maybe SDCRShadow has one of its top two bits set before you call SPIInit()? If so, it might be starting a transfer at that point. Can you print that shadow register value (in hex) before and after calling SPIInit()?

The other thought I have is to edit SPIInit() to move the “dummy read to empty the buffer” to the very end of the function, after it’s configured the registers.

It’s possible that somehow the state machine for reading 8 bits on that clocked serial port isn’t set up correctly, so the first read comes up short. Your solution of a dummy read after init is a good one, as long as it isn’t going to throw the slave devices off to have a single bit clocked out.

Hi Tom,

As always, thanks for getting back to me.

I did a bit more digging and I am wondering if the Serial Port Status Register is the culprit?

I put some printf lines before and after the SPIInit and after the very first SPIRead (see below)

SDCRShadow before SPIInit =00
SDSR before SPIInit =0xc0

SDCRShadow after SPIInit but before 1st Read =0c
SDSR after SPIInit but before 1st Read=0xc0

SDCRShadow after 1st Read =0c
SDSR after 1st Read =0x00

Notice how SDSR is 0xc0 before and after the SPIInit(). Bits 6 & 7 are set prior to the first SPIRead. According to the Serial Port x Status Register description, bit 6 should always be 0. Bit 7 indicates there is a byte in the receive buffer. I am wondering if the SDSR register should be cleared after first power up?

BTW I am using SPI.LIB version 1.09. Not sure if there is a newer version?

For now the dummy read works for me. I do it without the CS so the SPI slave doesn’t recognize it.

Regrads