Yesterday 23:59
Forum: Capture Compare / PWM Modules and Enhanced versions
Starter: dansagenius
Views: 0
Replies: 1
Yesterday 23:08
Forum: Website / Forum Issues
Starter: hadv215
Views: 0
Replies: 1
Yesterday 16:51
Forum: Proton Plus Compiler v3
Starter: Les
Views: 0
Replies: 12
Yesterday 13:12
Forum: Website / Forum Issues
Starter: xelectro
Views: 0
Replies: 2
Yesterday 08:31
Forum: Proton Users File Server
Starter: Les
Views: 0
Replies: 0
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: How to Enable SDO2 16F26K22?464 days old

  1. #1
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    114
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.78 GB

    0 Not allowed!

    Default How to Enable SDO2 16F26K22?

    Hello,

    I am using this code to enable SDO2 (PORTB.3) pin.24 (PIC 18F26K22) , but does not work.
    For SPI Display.

    Code:
      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.
    Last edited by Mentcleer; 14th February 2016 at 11:29. Reason: Missing %

  2. #2
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    77
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    177.27 MB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hello.

    For 18F25K20 it is written that to enable SDO, must have corresponding TRIS bit cleared.
    I don't know if it is the same for your PIC and for SDO2.
    Just an idea.

    Bye

  3. #3
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    114
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.78 GB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi Broderic,

    I am sorry, I do not understand what you want to say.
    But something is missing or something is wrong with the code.

    THX.

  4. #4
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    77
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    177.27 MB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi Mentcleer.

    Maybe to enable SPI you need to set pin 5 of SSP2CON1 register, that is SSP2EN=1 (or SSP2CON1=%00100001).
    See Chapter 15 of the data sheet.

    Then you have to configure your port where you have SDO2 (portB.3):
    TRISBbits.TRISB3 =0b0 (you have to clear the bit I guess). This was what I intended before
    In Proton maybe: TRISB= %11110111 or something like that(in other words you have to put zero bit3 of portB).
    I don't know if this is the problem, but it is an idea.

    Bye

  5. #5
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    114
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.78 GB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi,

    At the moment the code does not work for enabled MSSP2. PortB1 and 2 SPI Mode 18F26K22

    New code:
    Code:
      SSP2CON1          = %00100001    ' Synchronous Serial Port Enable bit and 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

  6. #6
    Fanatical Contributor pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    3,040
    Thumbs Up
    Received: 29
    Given: 29
    Total Downloaded
    832.68 MB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Have you tried using the SPI Include, rather than setting up manually?

    Include "SPI.inc"

  7. #7
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    114
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.78 GB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi pic-ignorant,

    How works this library for enabled MSSP2 SPI

    Where is MSSP2 ?

    I saw this LINK

    Code: (Not works and give me a lot errors)

    Code:
    Include "SPI.inc"
    OpenSPI(SPI_FOSC_16, MODE_00, SMPEND)



    THX


    Last edited by Mentcleer; 15th February 2016 at 19:13. Reason: Bad code

  8. #8
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    501
    Thumbs Up
    Received: 61
    Given: 2
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi Mentcleer,
    I think it's too simple.
    Write Include "Amicsus18_SPI.inc" in your IDE.
    Make a copy of this file and rename it as "Amicus_SPI.inc".

    See line 38 and line 202 of the file:
    Change the $if (_device = _18F25K22) =>
    to: $if (_device = _18F23K22) Or (_device = _18F24K22) Or (_device = _18F25K22) Or (_device = _18F26K22)

    What is the difference between the PIC18F26K22 and the PIC18F25K22?
    Save and use.
    Regards
    Alberto
    [U]73's de Alberto ea3agv[/U]

  9. #9
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    114
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    1.78 GB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi AlbertoFS,



    (But Code does not work)...

    The "Amicus18_SPI.inc" there as two parts for MSSP1 and MSSp2.
    with "OpenSI2()" Selecting the DSO2.

    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:
    Code:
    $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

  10. #10
    Junior Member Broderic's Avatar
    Join Date
    Jan 2016
    Posts
    77
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    177.27 MB

    0 Not allowed!

    Default Re: How to Enable SDO2 16F26K22?

    Hi Mentcleer.

    Perhaps it can be useful to see your PIN connections for the SPI, your complete code and your scope with the use of this SDO2.

    What I posted in the Amicus18 section (Demo_ST7565R_SPI.BAS _MODIFIED FOR AMICUS18) worked, and I think that with minor modifications, it can work also with SDO2.
    My PIN connection was:

    CSIB of GLCD to pin C7
    RESET of GLCD to pin B0
    A0 of GLCD to pin C2
    SCL of GLCD to pin C3
    SI of GLCD to pin C5

    Are you using Amicus18? Is still your scope to avoid splitting graph on the GLCD?

    Bye

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. A/D Converter Interrupt Enable - help
    By CharlieBrown in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 23rd January 2011, 05:15
  2. Graphical LCD with double ENABLE
    By FesterPic in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 21st April 2007, 15:19
  3. Enable & Disable HSEROUT
    By crankshaft in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 17th March 2006, 06:26
  4. It's possible to enable two RS232 ports?
    By GAMBOA in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 18th January 2006, 08:04
  5. LCD-display whith 2 enable pins
    By Stijn in forum Wish List / Product Feedback
    Replies: 0
    Last Post: 6th January 2006, 13:37

Members who have read this thread since 9th May 2017, 09:00 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts