0
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\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
    Commented Jun 1, 2017 at 23:04

2 Answers 2

2
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ "tristate is low" and " SSP1 SSPEN is low" this is not the issue, in this case. \$\endgroup\$
    – BillyBag2
    Commented Jun 8, 2017 at 9:14
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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