Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 06 2019 JH
- */
- #ifndef _SPI_H
- #define _SPI_H
- #include "general.h"
- #include <xc.h>
- #include <stdint.h>
- #define SPI_SLAVE_ID 0x40
- #define SPI_SLAVE_ADDR 0x00 // A1=0,A0=0
- #define SPI_SLAVE_WRITE WRITE
- #define SPI_SLAVE_READ READ
- // MCP23S08 registers definition (default, see datasheet)
- #define SPI_SLAVE_IODIR 0x00
- #define SPI_SLAVE_IPOL 0x01
- #define SPI_SLAVE_GPINTEN 0x02
- #define SPI_SLAVE_DEFVAL 0x03
- #define SPI_SLAVE_INTCON 0x04
- #define SPI_SLAVE_IOCON 0x05
- #define SPI_SLAVE_GPPU 0x06
- #define SPI_SLAVE_INTF 0x07
- #define SPI_SLAVE_INTCAP 0x08
- #define SPI_SLAVE_GPIO 0x09
- #define SPI_SLAVE_OLAT 0x0a
- #define SPI_SCK_DIR TRISBbits.TRISB1
- #define SPI_SDI_DIR TRISBbits.TRISB2
- #define SPI_SDO_DIR TRISBbits.TRISB3
- /*
- #define SPI_SCK_DIR TRISBbits.TRISB1
- #define SPI_MISO_DIR TRISBbits.TRISB2
- #define SPI_MOSI_DIR TRISBbits.TRISB3
- */
- #define SPI_SS_SX1272_DIR TRISBbits.TRISB0
- #define SPI_SS_SX1272_LAT LATBbits.LATB0
- #define SPI_SS_LPS331AP_DIR TRISCbits.TRISC0
- #define SPI_SS_LPS331AP_LAT LATCbits.LATC0
- #define SPI_START 0
- #define SPI_STOP 1
- #define SPI_RESET_DISABLE OUTP_HIGH
- #define SPI_RESET_ENABLE OUTP_LOW
- void SPIInit(void); // init SPI in master mode
- void SPIWriteSX(UINT8_T regAddr, UINT8_T data_out); // write data to MCP23S08 register
- UINT8_T SPIReadSX(UINT8_T regAddr); // read data from MCP23S08 register
- #endif /* _SPI_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement