I'm trying to get a PIC processor to communicate over CAN bus, using the MCP2515 interface chip. I have to communicate with the interface over SPI, and I do have it working, but the problem I'm having is that data into the processor always gets read as 0x00. This processor has Peripheral Pin Select, so I've chosen pins for the interface, and I'm pretty sure I got it right, because the SPI clock and data-out lines work fine. I've tried various pins for data-in, but it never works. I have made sure that whichever pin I use, the right TRIS bit is a 1 for an input, and all the ANSEL bits are set to 0. I've got a work-around by bit-banging my own SPI interface, and that works OK, but hardware SPI would be faster.
Here's how I set the PPS register. I've verified that it really does get set, by reading it back.
Then I write and read the SPI by just doing
ssp1buf = output;
then after a short delay
input = ssp1buf;
Ideas appreciated.
Here's how I set the PPS register. I've verified that it really does get set, by reading it back.
Code:
pps_unlock();
ra1pps = 0b00011000; // SPI clock to A1
b5pps = 0b00011001; // SPI MOSI to B5
ssp1datpps = 0b00010000; // C0 for SPI MISO
ssp1stat = 0b01000000;
ssp1con1 = 0b00100010; // Clock normally low
pps_lock();
ssp1buf = output;
then after a short delay
input = ssp1buf;
Ideas appreciated.