//======================================================================== // This library derived from skSPIlib.h below and was modified for // use of two SPI(SPI1 and SPI2) interfaces. // 2022.04.03 Tosh_Kojima //======================================================================== /******************************************************************************* * skSPIlib.h - SPI通信を行う関数のインクルードファイル(16ビットMCU専用) * * (PIC 24EP256MC202) PIC24F(24FJ64GB002) * * * * ============================================================================ * * VERSION DATE BY CHANGE/COMMENT * * ---------------------------------------------------------------------------- * * 1.00 2015-07-30 きむ茶工房 Create * * 1.10 2016-06-14 きむ茶工房(きむしげ) SPI_MODEのCKE(クロック位相)を変更 * * 1.20 2019-01-08 きむ茶工房(きむしげ) PIC24F動作確認 * *******************************************************************************/ #ifndef _SKSPILIB_H_ #define _SKSPILIB_H_ #define SPI1_USE //SPI1を使用するときはアンコメント、使用しない時はコメントアウト #define SPI2_USE //SPI2を使用するときはアンコメント、使用しない時はコメントアウト // 定数の定義 #ifndef LOW #define LOW 0 #endif #ifndef HIGH #define HIGH 1 #endif #ifdef SPI1_USE //------------------------------------------------------------ #define SPI1_MODE1 1 // クロック極性(0:LOW) クロック位相(0:アイドル0Vで、0V->5Vに変化で転送) #define SPI1_MODE0 0 // クロック極性(0:LOW) クロック位相(1:アイドル0Vで、5V->0Vに変化で転送) #define SPI1_MODE3 3 // クロック極性(1:HIGH) クロック位相(0:アイドル5Vで、5V->0Vに変化で転送) #define SPI1_MODE2 2 // クロック極性(1:HIGH) クロック位相(1:アイドル5Vで、0V->5Vに変化で転送) #define SPI1_PPRE_DIV1 3 // プライマリプリスケールの分周 1:1 #define SPI1_PPRE_DIV4 2 // プライマリプリスケールの分周 4:1 #define SPI1_PPRE_DIV16 1 // プライマリプリスケールの分周 16:1 #define SPI1_PPRE_DIV64 0 // プライマリプリスケールの分周 64:1 #define SPI1_SPRE_DIV1 7 // セカンダリプリスケールの分周 1:1 #define SPI1_SPRE_DIV2 6 // セカンダリプリスケールの分周 2:1 #define SPI1_SPRE_DIV3 5 // セカンダリプリスケールの分周 3:1 #define SPI1_SPRE_DIV4 4 // セカンダリプリスケールの分周 4:1 #define SPI1_SPRE_DIV5 3 // セカンダリプリスケールの分周 5:1 #define SPI1_SPRE_DIV6 2 // セカンダリプリスケールの分周 6:1 #define SPI1_SPRE_DIV7 1 // セカンダリプリスケールの分周 7:1 #define SPI1_SPRE_DIV8 0 // セカンダリプリスケールの分周 8:1 // SPI1(MSSP1)を利用する場合のレジスター定義 #define SPI1_CON1 SPI1CON1 #define SPI1_BUF SPI1BUF #define SPI1_IF _SPI1IF #define SPI1_STAT_SPIEN SPI1STATbits.SPIEN // 関数のプロトタイプ宣言 void SPI1_Init(char mode,char divider,int sdo) ; void SPI1_setDataMode(char mode) ; void SPI1_setClockDivider(char divider1,char divider2) ; unsigned char SPI1_transfer(char dt) ; #endif //------------------------------------------------------ #ifdef SPI2_USE //------------------------------------------------------------ #define SPI2_MODE1 1 // クロック極性(0:LOW) クロック位相(0:アイドル0Vで、0V->5Vに変化で転送) #define SPI2_MODE0 0 // クロック極性(0:LOW) クロック位相(1:アイドル0Vで、5V->0Vに変化で転送) #define SPI2_MODE3 3 // クロック極性(1:HIGH) クロック位相(0:アイドル5Vで、5V->0Vに変化で転送) #define SPI2_MODE2 2 // クロック極性(1:HIGH) クロック位相(1:アイドル5Vで、0V->5Vに変化で転送) #define SPI2_PPRE_DIV1 3 // プライマリプリスケールの分周 1:1 #define SPI2_PPRE_DIV4 2 // プライマリプリスケールの分周 4:1 #define SPI2_PPRE_DIV16 1 // プライマリプリスケールの分周 16:1 #define SPI2_PPRE_DIV64 0 // プライマリプリスケールの分周 64:1 #define SPI2_SPRE_DIV1 7 // セカンダリプリスケールの分周 1:1 #define SPI2_SPRE_DIV2 6 // セカンダリプリスケールの分周 2:1 #define SPI2_SPRE_DIV3 5 // セカンダリプリスケールの分周 3:1 #define SPI2_SPRE_DIV4 4 // セカンダリプリスケールの分周 4:1 #define SPI2_SPRE_DIV5 3 // セカンダリプリスケールの分周 5:1 #define SPI2_SPRE_DIV6 2 // セカンダリプリスケールの分周 6:1 #define SPI2_SPRE_DIV7 1 // セカンダリプリスケールの分周 7:1 #define SPI2_SPRE_DIV8 0 // セカンダリプリスケールの分周 8:1 // SPI2(MSSP2)を利用する場合のレジスター定義 #define SPI2_CON1 SPI2CON1 #define SPI2_BUF SPI2BUF #define SPI2_IF _SPI2IF #define SPI2_STAT_SPIEN SPI2STATbits.SPIEN // 関数のプロトタイプ宣言 void SPI2_Init(char mode,char divider,int sdo) ; void SPI2_setDataMode(char mode) ; void SPI2_setClockDivider(char divider1,char divider2) ; unsigned char SPI2_transfer(char dt) ; #endif //------------------------------------------------------ #endif