Autor Tema: Como Activar SDO2 del 18F26K22  (Leído 2997 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Enner

  • PIC10
  • *
  • Mensajes: 47
Como Activar SDO2 del 18F26K22
« en: 14 de Febrero de 2016, 17:47:47 »
Hola de nuevo,

Estoy intentando controlar  un display SPI y va bien cuando lo pongo en los pines por defecto que otorga SDO(1)del pic, pero necesito esos pines que me suministra
para otras cosas, este micro tinene dos MSSP, cuando intento poner SDI y CLK del display en los pines SDO2(RB3 Pin24) y CLK2 (RB1 pin.22)
con este código de inicio para SDO2 no funciona.

Falta algo o esta erroneo. ¿?

Código:

Código: [Seleccionar]
  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)

Gracias.


Desconectado Enner

  • PIC10
  • *
  • Mensajes: 47
Re:Como Activar SDO2 del 18F26K22
« Respuesta #1 en: 16 de Febrero de 2016, 15:32:04 »
Hola,

Demomento sin resutados fracaso total......:(

He puesto la libreria SPI de Amicus  "Amicus18_SPI.inc"  he incluido OpenSI2(),
para poder habilita el SPI2 y nada.

Alguna Idea¿..?


Codigo:
Código: [Seleccionar]
Include "Amicus18_SPI.inc"
OpenSPI2 (SMPEND, MODE_00, SPI_FOSC_16)

Libreria entera solo para SPI2 de Amicus:

Código: [Seleccionar]
$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


Gracias.

Desconectado dogflu66

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 3549
Re:Como Activar SDO2 del 18F26K22
« Respuesta #2 en: 19 de Febrero de 2016, 13:08:48 »
Hola; ¿Qué modelo de LCD estás usando?, hace tiempo que quiero hacer unas practicas y lo mismo me lo pido.
Saludos desde Granada, España.

Desconectado w3-sistemas

  • PIC12
  • **
  • Mensajes: 89
Re:Como Activar SDO2 del 18F26K22
« Respuesta #3 en: 19 de Febrero de 2016, 13:49:52 »
hola, yo estoy usando el mismo pic, con la salida spi pero para encender pixel led, me esplicas como es el funcionamiento de tu display para ver si te puedo ayudar