RCM6000 SPI on Port C

Dynamic C 10.72D, RCM6700 as SPI master, using SPI.LIB on serial port C. MCLK on PD2, MOSI on PC3, MISO on PC2.
On the Oscilloscope, I can see all signals, both those sent from the RCM6700, and the SDO from the device. (I tested the hardware by writing my own bit-bang version and it works but its way too slow) For the test, I slowed the MCLK down using the SPI_CLK_DIVISOR so it runs about as fast as my bit-bang. The device in the test is a 12-bit ADC from microchip, MCP3208.

I send data, but data that I read mirrors what I sent, not what the device sent. I am clearly missing something about the reception of the data

Code used to test -

#define CLOCK_PORT D
#define CLOCK_BIT 2
#define SPI_SER_C
#define SPI_CLK_DIVISOR 200
#define SPI_CLOCK_MODE  0
#use SPI.LIB

void main( void ){
	char data[80], Dst[80];
   char control;
   char channel;
   char ndata;
   char len;

   WrPortI( SPCR, &SPCRShadow, 0x84 ); // Parallel port A is a byte-wide output. used for CS

   BitWrPortI( PDDDR, &PDDDRShadow, 1, 2 ); // MCLK output
   BitWrPortI( PDDCR, &PDDCRShadow, 0, 2 ); // MCLK drive high-low

   BitWrPortI( PCDDR, &PCDDRShadow, 1, 3 ); // MOSI or SDI is an output
   BitWrPortI( PCDCR, &PCDCRShadow, 0, 3 ); // MOSI drive high-low

   BitWrPortI( PCDDR, &PCDDRShadow, 0, 2 ); // MISO or SDO is an input

   BitWrPortI(PCFR, &PCFRShadow,1,2); // special function the PC2 pin for MISO
   BitWrPortI(PCFR, &PCFRShadow,1,3); // special function the PC3 pin for MOSI
   WrPortI(PCALR, &PCALRShadow, RdPortI(PCALR) & ~0xF0); // alternate PC2, PC3 as TXC and RXC

   // special function the PD2 pin for MCLK on SCLKC
   BitWrPortI(PDFR, &PDFRShadow,1,2);
   WrPortI(PDALR, &PDALRShadow, RdPortI(PDALR) & ~0x30); // alternate select PD2 as SCLKC

	control = ( 0x10+0x08+( channel & 0x07 ) );

		   data[0] = control>>2;
		   data[1] = control<<6;
		   data[2] = 0x00;
         len = 3;

      	WrPortI( PADR, &PADRShadow, ~(1<<3) );
		   SPIWrRd( (char *) data, (char *) &Dst, ndata );
      	WrPortI( PADR, &PADRShadow, 0xFF );


Is this code based on Samples/SPI/spi_a2d-1.c, written for an LTC1294? It looks like a similar protocol, and you might be able to modify that sample to get it working with your hardware.

In your code where you’re setting PxALR registers, I think you should be using the shadow register instead of reading the register before modifying it.

WrPortI(PDALR, &PDALRShadow, PDALRShadow & ~0x30);

And with your chip select, you could use BitWrPortI() to toggle just the bit you’re interested in. Your current code doesn’t respect the other bits (always sets to 1), ignoring the values from in PADRShadow.

Hi Tom

On the use of PADR - I have a CS line on each of the pins on PADR so I select only 1 by setting all others to 1.

I think I did something very obviously wrong - my RX and TX are on the wrong pins for the SPI library.

MISO should be on PC3 and MOSI on pin PC2 :[

So did it start working once you swapped the pins?