Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.73 KB | None | 0 0
  1. /*
  2. 06 2019 JH
  3.  */
  4.  
  5. #ifndef _SPI_H
  6. #define _SPI_H
  7.  
  8. #include "general.h"
  9. #include <xc.h>
  10. #include <stdint.h>
  11.                
  12. #define SPI_SLAVE_ID            0x40
  13. #define SPI_SLAVE_ADDR          0x00      // A1=0,A0=0
  14. #define SPI_SLAVE_WRITE         WRITE
  15. #define SPI_SLAVE_READ          READ
  16.  
  17. // MCP23S08 registers definition (default, see datasheet)
  18. #define SPI_SLAVE_IODIR         0x00
  19. #define SPI_SLAVE_IPOL          0x01
  20. #define SPI_SLAVE_GPINTEN       0x02
  21. #define SPI_SLAVE_DEFVAL        0x03
  22. #define SPI_SLAVE_INTCON        0x04
  23. #define SPI_SLAVE_IOCON         0x05
  24. #define SPI_SLAVE_GPPU          0x06
  25. #define SPI_SLAVE_INTF          0x07
  26. #define SPI_SLAVE_INTCAP        0x08
  27. #define SPI_SLAVE_GPIO          0x09
  28. #define SPI_SLAVE_OLAT          0x0a
  29.  
  30.  
  31. #define SPI_SCK_DIR             TRISBbits.TRISB1
  32. #define SPI_SDI_DIR            TRISBbits.TRISB2
  33. #define SPI_SDO_DIR            TRISBbits.TRISB3
  34.  
  35. /*
  36. #define SPI_SCK_DIR             TRISBbits.TRISB1
  37. #define SPI_MISO_DIR            TRISBbits.TRISB2
  38. #define SPI_MOSI_DIR            TRISBbits.TRISB3
  39. */
  40. #define SPI_SS_SX1272_DIR           TRISBbits.TRISB0
  41. #define SPI_SS_SX1272_LAT           LATBbits.LATB0
  42.  
  43. #define SPI_SS_LPS331AP_DIR         TRISCbits.TRISC0
  44. #define SPI_SS_LPS331AP_LAT         LATCbits.LATC0
  45.  
  46.  
  47. #define SPI_START 0
  48. #define SPI_STOP 1
  49.  
  50. #define SPI_RESET_DISABLE       OUTP_HIGH
  51. #define SPI_RESET_ENABLE        OUTP_LOW
  52.  
  53.  
  54. void SPIInit(void);                                                         // init SPI in master mode
  55. void SPIWriteSX(UINT8_T regAddr, UINT8_T data_out);                       // write data to MCP23S08 register
  56. UINT8_T SPIReadSX(UINT8_T regAddr);                                       // read data from MCP23S08 register
  57.  
  58.  
  59. #endif  /* _SPI_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement