PIC32MX795F512H: SPI locks up PIC
I am trying to communicate with an lNAP375 over SPI. I set it up with:
SpiChnOpen(SPI_CHANNEL3, SPI_OPEN_MSTEN|SPI_OPEN_SMP_END|SPI_OPEN_MODE8|SPI_OPEN_CKE_REV, 80);
That yields a clock of 250kHz, the datasheet states a maximum of 11MHz and no minimum, so I think I'm ok there. I am trying to read register 0x72 which should contain a revision id. So I try this for reading:
CS2 = 0;
nTemp = SpiChnGetC(SPI_CHANNEL3);
CS2 = 1;
My oscilloscope shows this (clock is red, blue is MOSI, green is MISO, CS is not shown but applied correctly) (spi1.png)
The data is being transmitted correctly, but the response is weird. But it gets weirder...
The picture shows the first transmission after a cold start. If I send it again (same piece of code), it yields all zero. If I do it again, I again get zeros.
But if I send it a forth time, I get this (spi2.png)
That is the correct answer, a chip revision of '101' starting from the MSB, yielding 0xA8 in hex. But as soon as the SPI slave sends this answer, the PIC32 locks up and does not respond anymore. If I try this in a debugging session, the debugger does not jump to a position in my code. I can reset it, though, so it's not completely dead.
Now at least two questions arise...
Why does the SPI slave respond after the forth time I sent this, not the first time?
Why does the PIC32 lock up if it gets the correct data, and not in the other three cases?
On another project, I communicated with the lNAP375 using a PIC18F, without issues like these. Sent 0x72, sent dummy 0x00, got 0xA8 back. Everytime, all the time. Whats different here?