SDI pin MSSP

多くの PICマイコンに含まれている MSSP モジュールで SPI を使うときは、各ピンを適切に設定する必要があります。 PICの設計思想として、Function として使用しないピンはたとえファンクション設定がされていても、Direction レジスターによって機能を上書きできるようになっています。

Any serial port function that is not desired may be overridden by programming the corresponding data direction (TRIS) register to the opposite value. An example would be in master mode where you are only sending data (to a display driver), then both SDI and SS could be used as general purpose outputs by clearing their corresponding TRIS register bits.

ところが、初期 PICにはエラッタがあったために SDI の信号を Direction register (TRIS) で上書きすることができませんしたでした。そのためデータシートには

SDI is automatically controlled by the SPI module

という記載が SDI にだけされるようになりました。 この不具合は PIC16F87X の場合 Silicon Revision B4 で修正されたにも関わらず、まだ多くの最新版データーシートには「自動的に設定される」と前述の文字列が並んでいます。これは、すでに嘘であり SDI として使う場合には IN に drection を設定する必要があります。

DS31015A 1997 PICmicro™ Mid-Range MCU Family Reference Manual から引用すると

15.3.2 Enabling SPI I/O
To enable the serial port the SSP Enable bit, SSPEN (SSPCON<5>), must be set. To reset or reconfigure SPI mode, clear the SSPEN bit which re-initializes the SSPCON register, and then set the SSPEN bit. This configures the SDI, SDO, SCK, and SS pins as serial port pins. For the pins to behave as the serial port function, they must have their data direction bits (in the TRIS register) appropriately programmed. That is:

  • SDI must have the TRIS bit set
  • SDO must have the TRIS bit cleared
  • SCK (Master mode) must have the TRIS bit cleared
  • SCK (Slave mode) must have the TRIS bit set
  • SS must have the TRIS bit set

ということなので気をつけましょう。

https://www.microchip.com/forums/m42815.aspx