RB1 as CS
RB2 as SCK2
RB2 as SDI2
The relevant code is:
- Code: Select all
#include <pconfig.h>
#include <pps.h>
#include <spi.h>
ANCON0 = 0xFF; // Default all pins to digital
ANCON1 = 0xFF;
PPSUnLock();
PPSInput(PPS_SDI2, PPS_RP5); // Remap SDI2 to RP5 (RB2)
PPSOutput(PPS_RP13, PPS_SCK2); // Remap SCK2 to RP13 (RC2)
PPSLock();
OpenSPI2(SPI_FOSC_64, MODE_01, SMPMID);
LATBbits.LATB1 = 0; // Chip Select (active low)
unsigned char tmp = ReadSPI2();
LATBbits.LATB1 = 1;
I'm using a working USB connection to display debugging info. The return value of ReadSPI2 is always zero, even when I disconnect RB2 from the MAX31855 and connect it to VDD, when PORTBbits.RB1 returns 1.
It seems to me that, even if I've cooked the MAX chip, I should still get 0xff from the read - unless:
a: the pin remapping is wrong, or
b: there is a bug in the SPI library, or
c: I've done something really stupid
Please vote for a, b, or c.