18F16Q41 - #error _device + " does not support MSSP"

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
garryp4
Posts: 126
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

18F16Q41 - #error _device + " does not support MSSP"

Post by garryp4 » Sun Feb 18, 2024 5:44 pm

the data sheet shows the device has SPI1 and 2

Code: Select all

Device = 18F16Q41
Clock = 64

Config
  FEXTOSC = OFF,      // Oscillator not enabled
  RSTOSC = HFINTOSC_64MHZ,// HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
  CLKOUTEN = OFF,     // CLKOUT function is disabled
  PR1WAY = ON,        // PRLOCKED bit can be cleared and set only once
  CSWEN = ON,         // Writing to NOSC and NDIV is allowed
  FCMEN = OFF,        // Fail-Safe Clock Monitor disabled
  FCMENP = OFF,       // Fail-Safe Clock Monitor disabled
  FCMENS = OFF,       // Fail-Safe Clock Monitor Disabled
  MCLRE = EXTMCLR,    // If LVP=0, MCLR pin is MCLR; If LVP=1, RE3 pin function is MCLR
  PWRTS = PWRT_64,    // PWRT set at 64ms
  MVECEN = OFF,       // Interrupt contoller does not use vector table to prioritze interrupts
  IVT1WAY = ON,       // IVTLOCKED bit can be cleared and set only once
  LPBOREN = OFF,      // Low-Power BOR disabled
  BOREN = SBORDIS,    // Brown-out Reset enabled , SBOREN bit is ignored
  BORV = VBOR_2P85,   // Brown-out Reset Voltage (VBOR) set to 2.8V
  ZCD = OFF,          // ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
  PPS1WAY = OFF,      // PPSLOCKED bit can be set and cleared repeatedly (subject to the unlock sequence)    
  STVREN = ON,        // Stack full/underflow will not cause Reset
  LVP = ON,           // HV on MCLR/VPP must be used for programming
  XINST = OFF,        // Extended Instruction Set and Indexed Addressing Mode disabled
  WDTCPS = WDTCPS_0,  // Divider ratio 1:32
  WDTE = OFF,         // WDT Disabled; SWDTEN is ignored
  WDTCWS = WDTCWS_7,  // window delay = 50%; no software control; keyed access required
  WDTCCS = SOSC,      // WDT reference clock is SOSC
  BBSIZE = BBSIZE_512,// Boot Block size is 512 words
  BBEN = OFF,         // Boot block disabled
  SAFEN = OFF,        // SAF disabled
  DEBUG = OFF,        // Background Debugger disabled
  WRTB = OFF,         // Boot Block not Write protected
  WRTC = OFF,         // Configuration registers not Write protected
  WRTD = OFF,         // Data EEPROM not Write protected
  WRTSAF = OFF,       // SAF not Write Protected
  WRTAPP = OFF,       // Application Block not write protected
  CP = OFF            // PFM and Data EEPROM code protection disabled
  

#option USART1_TX = PORTA.4            ' 
#option USART1_RX = PORTA.5            '
#option USART2_TX = PORTC.1            ' 
#option USART2_RX = PORTB.5            '

#option SPI1_SCK   = PORTC.7           ' SPI clock
#option SPI1_SDI   = PORTC.3           ' SPI data in
#option SPI1_SDO   = PORTC.4           ' SPI data out

// import modules...
Include "intosc.bas"
Include "convert.bas"
Include "system.bas"
Include "USART.BAS"
Include "USART2.bas"
Include "setdigitalio.bas"
Include "string.bas"
Include "EEPROM.bas"
Include "pps.bas"
Include "spi.bas"


Private Dim
  red              As PORTC.0,         ' High to turn on
  blue             As PORTA.2,
  re               As PORTC.2,         ' Low to recieve
  de               As PORTB.4,         ' High to send
  int_1            As PORTC.5,         ' Accel int 1
  int_2            As PORTB.7,         ' Accel int 2
  a_cs             As PORTC.6,         ' Accel chip select
  m_cs             As PORTB.6          ' Memory chip select
  
  
'****************************************************************************
Private Sub BLINK_LED()
  High(red)
  DelayMS(80)
  Low(red)
  High(blue)
  DelayMS(80)
  Low(blue)
End Sub
'****************************************************************************
Private Sub SET_TERM_SERIAL()
pps.unlock()
  ' USART1
  Input(PORTA.5)                       ' Make RX1 pin an input
  U1RXPPS = $05                        ' RA5 > RX1
  Output(PORTA.4)                      ' Make TX1 pin an output
  RA4PPS = $10                         ' TX1 > RA4  
pps.lock()
USART.SetBaudrate(br9600)              ' Baud rate
USART.ReadTerminator = 13              ' CR
End Sub
'****************************************************************************
Private Sub SET_485_SERIAL()
pps.unlock()
  ' USART2
  Input(PORTB.5)                       ' Make RX2 pin an input
  U2RXPPS = $0D                        ' RB5 > RX2
  Output(PORTC.1)                      ' Make TX2 pin an output
  RC1PPS = $13                         ' TX2 > RC1  
pps.lock()
USART2.SetBaudrate(br9600)             ' Baud rate
USART2.ReadTerminator = 13
End Sub
'****************************************************************************
Public Sub SET_SPI()
pps.unlock()
  'Module: SPI2
  SPI1SCKPPS = $17                     'RC7 > SCK2
  RC7PPS = $1B                         'SCK1 > RC7 (bidir)
  SPI1SDIPPS = $14                     'RC4 > SDI1
  RC5PPS = $1C                         'SDO1 > RC5
pps.lock()
'****************************************************************************

End Sub
SetAllDigital()
PMD0 = $3D                             ' Clock stuff enabled
PMD1 = $F0                             ' Timers enabled
PMD2 = $E7                             ' Clock stuff enabled, DAC ADC disabled
PMD3 = $2F                             ' USART1,2 AND SPI1 enabled
PMD4 = $FF                             ' USART3 disabled
PMD5 = $FF                             '


Low(blue)
Low(red)
Input(re)
Input(de)
Input(int_1)
Input(int_2
High(a_cs)
High(m_cs)


Private Dim
  b1          As Byte,
  w1          As Word,
  w_dat       As Word,  
  lp1         As Byte,
  lp2         As Word,
  lp3         As Word,
  c1          As Char,
  mem         As Byte,
  acc_loops   As Word,
  loops       As Word,
  x_li_l      As LongInt,
  y_li_l      As LongInt,
  z_li_l      As LongInt,
  x_li_h      As LongInt,
  y_li_h      As LongInt,
  z_li_h      As LongInt,
  x_diff      As Integer,
  y_diff      As Integer,
  z_diff      As Integer,
  mem_xyz     As memory_XYZ,
  int_XYZ     As integer_XYZ,
  x_dat(112)  As Word,
  y_dat(112)  As Word,
  z_dat(112)  As Word,
  x_data(112) As Integer,
  y_data(111) As Integer,
  z_data(111) As Integer
Thanks

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: 18F16Q41 - #error _device + " does not support MSSP"

Post by Jerry Messina » Sun Feb 18, 2024 11:12 pm

The library files SPI.bas and SPI2.bas are for use with devices that have an MSSP peripheral.
For the new xv18 core devices with individual SPI and I2C peripherals, use SPIxv.bas and SPI2xv.bas.

The defines/options might be a little different, so check them out.
You'll definitely have to map the pins using PPS, that much I remember.

garryp4
Posts: 126
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

Re: 18F16Q41 - #error _device + " does not support MSSP"

Post by garryp4 » Mon Feb 19, 2024 7:56 pm

Thanks, that was it.

Post Reply