News:

;) This forum is the property of Proton software developers

Main Menu

Preprocessor 8b MCU SPI type (new or old type) select

Started by trastikata, Feb 11, 2026, 07:38 PM

Previous topic - Next topic

trastikata

Hello Les,

is it possible for the Preprocessor to select based on the type of SPI used in the device i.e. the new 8b Q-micros or the classic SPI register set?

Thank you.

top204

The only thing the preprocessor can do for that type of comparison, is look at the SFRs in the .def file, and if a certain SFR is present, then it is a particular SPI mechanism.

Microchip are notorious for changing things for very little reason.

Regards
Les

trastikata

Quote from: top204 on Today at 10:17 AMThe only thing the preprocessor can do for that type of comparison, is look at the SFRs in the .def file, and if a certain SFR is present, then it is a particular SPI mechanism.

Perfect, thank you Les.

This did the job because the new SPI registers set use SPIxRXB and SPIxTXB instead of the old SSPxBUF to hold TX/RX data.

'Device 18F57Q83
Device = 18F67K22
Declare Xtal 4

$ifdef _SPI1TXB
    $define SPI_MODE 1
$else   
    $ifdef _SSP1BUF    
        $define SPI_MODE 0
    $endif
$endif   

$if SPI_MODE = 1
    SPI1CON0.7 = 1
    SPI1CON1.6 = 1
    SPI1BAUD = 1

    SPI2CON0.7 = 1  
    SPI2CON1.6 = 1
    SPI2BAUD = 1
$elseif SPI_MODE = 0
    SSP1STAT.6 = 1
    SSP1CON1 = %00100000
   
    SSP2STAT.6 = 1
    SSP2CON1 = %00100000
$endif