Hi guys
I am trying to set the MSSP1,2 SPI with the PSS control of the pins and like to confirm i have it correct for the 18f47k40
first time using MSSP with PPS chip with this arrangement
also like to confirm SS pin when SSP2 set as slave , when selected as not used is free for other I/O use
using MPLAB - code configure as guide , it gives warnings on SS is allocated incorrectly , also that SCK2 has no output,( it a slave so there is none ),
- can SS pin for SPI slave NOT be assigned and is free for other I/O
i am aware the data pins for both SSP must be allocated even if not used , week pullups assigned to those
Requirement>
have MSSP1 as master, generate clock output from clk pin , usedata from buffer byte for SSP1 , no data input pin required , no slave SS output to slave
Have MSSP2 as slave , recieve clock in , use data from buffer byte for SSP2, no data input pin required , no slave SS pin used / required
USE: generate 2 seperate spi data streams based off the master generated clock , with slave clock in wire linked to master clock out
Cheers
Sheldon
PPS pin allocation of MSSP1,2 requirement shown here
I am trying to set the MSSP1,2 SPI with the PSS control of the pins and like to confirm i have it correct for the 18f47k40
first time using MSSP with PPS chip with this arrangement
also like to confirm SS pin when SSP2 set as slave , when selected as not used is free for other I/O use
using MPLAB - code configure as guide , it gives warnings on SS is allocated incorrectly , also that SCK2 has no output,( it a slave so there is none ),
- can SS pin for SPI slave NOT be assigned and is free for other I/O
i am aware the data pins for both SSP must be allocated even if not used , week pullups assigned to those
Requirement>
have MSSP1 as master, generate clock output from clk pin , usedata from buffer byte for SSP1 , no data input pin required , no slave SS output to slave
Have MSSP2 as slave , recieve clock in , use data from buffer byte for SSP2, no data input pin required , no slave SS pin used / required
USE: generate 2 seperate spi data streams based off the master generated clock , with slave clock in wire linked to master clock out
Cheers
Sheldon
PPS pin allocation of MSSP1,2 requirement shown here
Code:
' ------- Port B Settings & directions ----------
ANSELB = %00000000 ' Set PortB Analog bit7-0 = ANB7-0 / 0 = digital ,1= Analog ,
TRISB = %10110010 '
WPUB = %00110000 ' Set Week Pullups on Digital inputs POR =0
INLVLB = %11111111 ' Set Input levels - Schmitt = 1 / TTL = 0 POR = 1
SLRCONB = %11111111 ' Set Slew Rate 1 = Rate Limited 0 = Max rate POR =1
IOCBP = %00000000 ' IOC Positive Edge Trigger Select RB7-RB0 0 = diabled 1 = enabled POR = 0
IOCBN = %00000000 ' IOC Negative Edge Trigger Select RB7-RB0 0 = diabled 1 = enabled POR = 0
ODCONB = %00000000 ' Open Drain 0 = Output drives both High and Low signals 1= Output drives Low going signals only POR = 0
' ------- Setup port B Variables ----------
LATB = $00 ' Clear Outputs
SSP1_CLKout VAR LATB.0 ' (active high)
SSP2CLKIN VAR PORTB.1 ' wired to portb.0
SSP1_data VAR LATB.2 ' SSP1_SDO DATA OUT
SSP2_data VAR LATB.3 ' ,SSP2_SDO DATA OUT
SSP2_SDI VAR PORTB.4 ' MSSP2 IN - MUST ASSIGN PIN , BUT NOT CONNECTED
SSP1_SDI VAR PORTB.5 ' MSSP1 IN - MUST ASSIGN PIN , BUT NOT CONNECTED
' NOTE: USB-TX2,RX2 - PORTB.6,7 Set by Defines for terminal2 services
Code:
RB0PPS =$0F ' MSSP1(SCK OUTPUT) SCK SPI MASTER - PORTB.0 USED
RB2PPS =$10 ' MSSP1(SDO OUTPUT) SSP1_data SPI MASTER - PORTB.2 USED ( PCB REWIRED PORTA.5 TO SUIT )
SSP1CLKPPS=$08 ' MSSP1(SCK INPUT) MSSP1 CLK SPI MASTER - INPUT MUST BE SET THE SAME PIN AS MSSP1 OUTPUT - PORTB.0 FOR PPS
SSP1DATPPS=$0D ' MSSP1(SDO INPUT) MSSP1 SDI-1 SPI MASTER - INPUT NOT USED BUT MUST BE SET - PIN CANT BE USED FOR OTHER ASSINGMENTS AND IS LEFT NOT CONNECTED - RE-ASIGNED PORTB.5 - RTC_32KHZ
'SSP1SSPPS=NA' ' MSSP1(SS1 INPUT) NOT REQUIRED - DISABLED - NORMAL I/O USE OF PIN '
RB1PPS =$11 ' MSSP2(SCK OUTPUT) MSSP2 CLK SPI SLAVE - OUTPUT MUST BE SET THE SAME PIN AS MSSP2 INPUT PORT PORTB.1 FOR PPS
RB3PPS =$12 ' MSSP2(SDO OUTPUT) SSP2_data SPI SLAVE - PORTB.3 USED ( PCB REWIRED PORTA.6 TO SUIT )
SSP2CLKPPS=$09 ' MSSP2(SCK INPUT) MSSP2 CLK SPI SLAVE - INPUT MUST BE SET THE SAME PIN AS MSSP1 OUTPUT - PORTB.1 FOR PPS
SSP2DATPPS=$0C ' MSSP2(SDO INPUT) MSSP2 SDI-1 SPI SLAVE - INPUT NOT USED BUT MUST BE SET - PIN CANT BE USED FOR OTHER ASSINGMENTS AND IS LEFT NOT CONNECTED - RE-ASIGNED PORTB.4 - HUB_A
'SSP2SSPPS=NA' ' MSSP2(SS2 INPUT) NOT REQUIRED - DISABLED - NORMAL I/O USE OF PIN '
' -----------MSSP1 & MSSP2 - HARDWARE SPI/I2C SETTINGS ----------------
SSP1STAT = $40 '0100 0000 - bit7 = 0 spi master-sample middle of data output tim, bit6= 1 spi tx occures from active to idel state
SSP1CON1 = $2A '0010 1010 - bit7,6 = x,bit5= spien 1=spi enable - set sck, sdo,sdi ssx pins bit4 = spi ckp 1 =clock idle high 0 = clk idel low,bit3-0- 1010= spi master fosc/4 sspxadd >=1
SSP1ADD = 1 ' set master spi address = 1 - cant be 0
SSP2STAT = $40 '0100 0000 bit7 spi slave mode = bit must be 0 ,
SSP2CON1 = $25 '0010 0101 bit 7,6= x, bit 5= spien 1=spi enable ,bit4 0 = clk idle low bit3-0= 0101 spi slave mode SSx pin control disabled
SSP2CON3 = $0