I am trying to program a PIC16F18877 I have some auto generated code that sets up SPI on some pins. (eg RC4) I have a device that is not SPI properly so wish to Bit Bash it. How do I switch the PIN back to GPIO usage? There are PPS registers that control which pins the SPI uses but not sure how to just "turn it off" and switch it back to GPIO usage. I don't want to redirect the SPI somewhere else.

EDIT: The pin is being driven low when latch is high and tristate is low. There is an external pull up. Setting tristate high causes the pin to go high, both on the scope and the port register. So the pin is being driven low by the PIC even when SSP1 SSPEN is low?

  • \$\begingroup\$ Still not working. Very strange. The SSPEN is now false. The tri state is false, I can see the value written to the latch but pin is not set when I read the port. \$\endgroup\$ – BillyBag2 Jun 1 '17 at 23:04

It seems that what you want to achieve is to use the standard pins of the SPI1 peripheral, except the SDI1 pin (since you specified pin RC4, which corresponds to the SDI1 pin). Consider the following extract from the PIC16F8877 datasheet:

SSPEN options

From this extract it seems that if you make SSPEN = 0, then it would disable all of the SPI peripheral's pins. Do you mean that you ONLY want to disable the SDI1 pin, and use the rest of the SPI pins (SCK, SDO and SS) as per normal through the SPI peripheral? If that is the case, I am not entirely sure if that is possible to achieve (I have never tried it myself).

However, you do not make any mention of the TRIS register settings. The datasheet specifically mentions that even though you enable the SPI peripheral, you still need to set the appropriate TRIS register settings (see section 31.2.2 in the datasheet). Did you configure the TRISC4 register bit (assuming pin RC4 is the pin in question) as an input?

| improve this answer | |
  • \$\begingroup\$ "tristate is low" and " SSP1 SSPEN is low" this is not the issue, in this case. \$\endgroup\$ – BillyBag2 Jun 8 '17 at 9:14

The issue, in this case, was that I was unaware that the are actually two PPS registers. (RTFM) One for input and one for output. The PPS register that controls which peripheral drives a pin needs to be set to zero, meaning GPIO.

eg. RC3PPS = 0; RC2PPS = 0; RC4PPS = 0;

I was trying to "undo"... SSP1CLKPPS = XYZ; SSP1DATPPS = ABC;

Which is only to do with inputs to the SSP and does not need to be "undone" to switch the port back to a GPIO. (Setting SSPEN low may be required but I was already doing this.)

Thanks everyone.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.