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_RX_PORT SPI_RX_PC
#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
SPIinit();
SPImode(0);
channel=7;
control = ( 0x10+0x08+( channel & 0x07 ) );
while(1){
costate{
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 );
for(ndata=0;ndata