Hello,
I am using this code to enable SDO2 (PORTB.3) pin.24 (PIC 18F26K22) , but does not work.
For SPI Display.
Something is missing or something is wrong with the code.
Code Active SPI (SDO2)
SSP2CON1= %00000001 ' Clock FOSC/16 '%
Symbol SSP2EN = SSP2CON1.5 ' SSP Enable bit
Symbol CKP2 = SSP2CON1.4 ' Clock Polarity Select
Symbol SMP2 = SSP2STAT.7 ' Data input sample bit
Symbol CKE2 = SSP2STAT.6 ' Clock Edge Select bit
Symbol BF2 = SSP2STAT.0 ' buffer full status bit 1 = buffer full
Symbol SSP2IF = PIR3.7 ' Synchronous Serial Port Interrupt Flag Bit
OSCCON= %01110000 ' HFINTOSC – (16 MHz)'%
THX
Are you able to send any code from spi2 to outside? Could you check it with any logic analyzer? if it is okay, your lcd configurations or anything has a problem. if it is not okay, you must solve opening spi2 unit correctly.
Best Regards,
Karamel
it must be digital I/O. Did you make it ?
Hello,
My question is that if the code is good for the open MSSP2 Pic 18F26K22 PortB.
For now, it does not work.
New Code: (does not work.)
SSP2CON1= %00100001 ' Clock FOSC/16 '%
Symbol SSP2EN = SSP2CON1.5 ' SSP Enable bit
Symbol CKP2 = SSP2CON1.4 ' Clock Polarity Select
Symbol SMP2 = SSP2STAT.7 ' Data input sample bit
Symbol CKE2 = SSP2STAT.6 ' Clock Edge Select bit
Symbol BF2 = SSP2STAT.0 ' buffer full status bit 1 = buffer full
Symbol SSP2IF = PIR3.7 ' Synchronous Serial Port Interrupt Flag Bit
OSCCON= %01110000 ' HFINTOSC – (16 MHz)'%
TRISB= %00000000 'All PortB Outs
THX.
Nope. kantirici mentor has said that you must define digital i-o these pins of port. Actually, i have worked with picmicrocontrollers for very short times but i can remember that these family must be had a ADCON e.t registers. Thus, you must arrange this register for digital io selections.
You can also ask your questions which are about pic basic pro or pic microcontrollers to
@Maxim mentor
Good luck.
Hi Karamel,
The PortB already enabled I / O digital.
THX.
Hi,
(But Code does not work)...
The "Amicus18_SPI.inc" there as two parts for SPI1 and SPI2.
with "OpenSI2()" Selecting the DSO2 (SPI2).
I have also tried all the pSyncMode, pBusMode, pSmpPhase... Nothing..!!
I have included this:
Include "Amicus18_SPI.inc"
OpenSPI2 (SMPEND, MODE_00, SPI_FOSC_16)
Code OpenSPI2 (only):
$ifndef __SPI_INC_
$define __SPI_INC_
'
' SPI peripheral library for Amicus18
'
$define SMPEND %10000000 ' Input data sample at end of data out
$define SMPMID %00000000 ' Input data sample at middle of data out
$define MODE_00 %00000000 ' Setting for SPI bus Mode 0,0
$define MODE_01 %00000001 ' Setting for SPI bus Mode 0,1
$define MODE_10 %00000010 ' Setting for SPI bus Mode 1,0
$define MODE_11 %00000011 ' Setting for SPI bus Mode 1,1
' SSPCON1 Register
$define SSPENB %00100000 ' Enable serial port and configures SCK, SDO, SDI
$define SPI_FOSC_4 %00000000 ' SPI Master mode, clock = Fosc/4
$define SPI_FOSC_16 %00000001 ' SPI Master mode, clock = Fosc/16
$define SPI_FOSC_64 %00000010 ' SPI Master mode, clock = Fosc/64
$define SPI_FOSC_TMR2 %00000011 ' SPI Master mode, clock = TMR2 output/2
$define SLV_SSON %00000100 ' SPI Slave mode, /SS pin control enabled
$define SLV_SSOFF %00000101 ' SPI Slave mode, /SS pin control disabled
'***************************************************************
' Amicus18 Revision 2
'***************************************************************
$if (_device = _18F26K22)
'-----------------------------------------------------------------------------------
' CloseSPI2
$define CloseSPI2() SSP2CON1 = SSP2CON1 & $DF
'-----------------------------------------------------------------------------------
' DataReadySPI2: Test if SSP2BUF register is full
$define DataReadySPI2() SSP2STATbits_BF
'-----------------------------------------------------------------------------------
' Macro Name : OpenSPI2
' Return Value : None
' Parameters : SSP2 peripheral setup values
' Notes : Sets up the SSP2 module for master or slave operation
'
' Syntax OpenSPI2 pSyncMode , pBusMode , pSmpPhase
'
$define OpenSPI2(pSyncMode,pBusMode,pSmpPhase) _OpenSPI2 pSyncMode, pBusMode, pSmpPhase
_OpenSPI2 Macro- pSyncMode, pBusMode, pSmpPhase
SSP2STAT = SSP2STAT & $3F ' Power on state
SSP2CON1 = $00 ' Power on state
#if(pSyncMode != 0)
Movlw (pSyncMode)
Iorwf SSP2CON1,f ' Select serial mode
#endif
#if(pSmpPhase != 0)
Movlw (pSmpPhase)
Iorwf SSP2STAT,f ' Select data input sample phase
#endif
#if(pBusMode == 0) ' SPI bus mode 0,0
SSP2STATbits_CKE = 1 ' Data transmitted on rising edge
#endif
#if(pBusMode == 2) ' SPI bus mode 1,0
SSP2STATbits_CKE = 1 ' Data transmitted on falling edge
SSP2CON1bits_CKP = 1 ' Clock idle state high
#endif
#if(pBusMode == 3) ' SPI bus mode 1,1
SSP2CON1bits_CKP = 1 ' Clock idle state high
#endif
#if(pSyncMode == 4) ' Slave mode with /SS enable
TRISB.1 = 1 ' Define clock pin as input
TRISB.0 = 1 ' Define /SS2 pin as input
#endif
#if(pSyncMode == 5) ' Slave mode without /SS enable
TRISB.1 = 1 ' Define clock pin as input
#else ' Master mode, define clock pin as output
TRISB.1 = 0 ' Define clock pin as output
#endif
TRISB.2 = 1 ' Define SDI pin as input
TRISB.3 = 0 ' Define SDO pin as output
SSP2CON1.5 = 1 ' Enable synchronous serial port
Endm
'-----------------------------------------------------------------------------------
' Macro Name : WriteSPI2
' Return Value : Input data can be picked up by reading SSP2BUF straight after the WriteSPI2 macro
' Parameter : Single 8-bit variable for SPI2 bus.
' Description : Write a single byte (8-bits) to the SPI2 bus.
'
$define WriteSPI2(pDataOut) '
WREG = pDataOut '
_WriteSPI2
_WriteSPI2 Macro-
GoSub __WriteSPI2
Endm
#ifMacro- _WriteSPI2
__WriteSPI2:
SSP2STATbits_BF = 0 ' Empty the SSP2BUF buffer flags
PIR3bits_SSP2IF = 0 ' Clear the interrupt flag
SSP2BUF = WREG ' Place the data to send into SSP2BUF
Btfss PIR3bits_SSP2IF ' \
Bra $ - 2 ' / Wait until cycle complete
WREG = SSP2BUF ' Read SSP2BUF into WREG
Return
#endIfMacro-
'-----------------------------------------------------------------------------------
' Macro Name : ReadSPI2
' Return Value : Contents of SSP2BUF register
' Parameters : None
' Description : Read byte\s from the SPI2 bus.
'
$define ReadSPI2() _ReadSPI2
_ReadSPI2 Macro- '\Byte
GoSub __ReadSPI2
Return_Wreg
Endm
#ifMacro- _ReadSPI2
__ReadSPI2:
WREG = SSP2BUF ' Empty the SSP2BUF buffer and clear flags
PIR3bits_SSP2IF = 0 ' Clear interrupt flag
SSP2BUF = $FF ' Initiate bus cycle
Btfss PIR3bits_SSP2IF ' \
Bra $ - 2 ' / Wait until cycle complete
WREG = SSPBUF ' Read SSP2BUF into WREG
Return
#endIfMacro-
$define SPI2_Write(pDataOut) WriteSPI2(pDataOut)
$define SPI2_Read() ReadSPI2()
$define SPI2_Open(pSyncMode,pBusMode,pSmpPhase) OpenSPI2(pSyncMode,pBusMode,pSmpPhase)
$define SPI2_DataReady() SSP2STATbits_BF
$define SPI2_Close() SSP2CON1 = SSP2CON1 & $DF
$endif
'---------------------------------------------------------
_SPI_MAIN_:
$endif
THX.