Electronic – Difference between SMPEND and SMPMID

cenc28j60picspixc8

I'm interfacing an SPI chip with a PIC18 device, programmed with a C program compiled with the XC8 compiler, using libraries from plib.h. In the docs, I read:

void OpenSPI( unsigned char sync_mode,
              unsigned char bus_mode,
              unsigned char smp_phase);

smp_phase
One of the following values, defined in spi.h:
SMPEND: Input data sample at end of data out
SMPMID: Input data sample at middle of data out

What does this parameter change?

I'm interfacing the ENC28J60, and found out that both values for smp_phase result in a working connection. Are there chips that wouldn't work with both values, and if not, what's the use of the setting?

Best Answer

As with all these kinds of low level issues, you have to read the datasheet. It's OK to call library routines, but on these small resource-limited systems where you're always close to the hardware, you have to know what's going on at the low level whether that is done in a library routine or your own code.

Read the SPI part of the chapter for the MSSP peripheral. That goes into some detail about these modes, and includes timing diagrams for the various combinations. I could copy some of that here, but that would be pointless as you need to read the datasheet anway.

This is a good example where just writing the code yourself would have actually been easier than calling a library routine. That is not because the call is hard, but to verify that someone else's library does exactly what you need takes longer than just setting up the hardware that way in the first place. There are only 2 8-bit registers to set up to use the MSSP, which should results in 4 instructions.