Question on SPI Data out on PortC.7(pic18f4550)


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Question on SPI Data out on PortC.7(pic18f4550)

    The following code is working...
    Code:
    SD_WE        Var    PORTA.4    ' SD card write protect
    SD_WE_TRIS    Var    TRISA.4    ' SD card write protect direction
    SDI        Var    PORTB.0    ' SPI data in
    SDI_TRIS    Var    TRISB.0    ' SPI data in direction
    SCL        Var    PORTB.1    ' SPI clock
    SCL_TRIS    Var    TRISB.1    ' SPI clock direction
    SD_CS        Var    PORTB.3    ' SD card chip select
    SD_CS_TRIS    Var    TRISB.3    ' SD card chip select direction
    SD_CD        Var    PORTB.4    ' SD card detect
    SD_CD_TRIS    Var    TRISB.4    ' SD card detect direction
    SDO        Var    PORTC.7    ' SPI data out
    SDO_TRIS    Var    TRISC.7    ' SPI data out direction
    My question now is it possible to use other pin for SDO? I see it on the datasheet for Pic18F4550 PORTRC.7 is RC7/RX/DT/SDO. I tried PortD.0 and PortB.7 but not working. The reason I want to use other pin is I'm planning to use it for blue tooth module and use hardware interrupt on PortC.7.


    Kind regards,
    tacbanon

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    Yes, if you are using software SPI. Then you can put SD pin's on almost any pin on PIC.

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    @pedja089
    Thanks for replying...I'm not really that good yet in PBP and not yet use shiftin/shiftout...but can you give a link where to start(good example) so that my end goal is to use it for the sdcard module?

    Thanks in advance,
    tacbanon

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    If you are using the SDFS from MeLabs it is built in.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    Hello macrackit, I will check it out..thanks.

    Kind regards,
    tacbanon

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    I'm trying to figure it out this block of code from SDFS how to make disable hardware SPI.
    Code:
    ' Initialize some values for the following subroutines
    	SDC_UseHardSPI = TRUE	' Use hardware SSP port for SPI.
    	DISK_mount = FALSE	' The card has not been initialized.
    	FAT_mode = "r"		' Read mode if not otherwise specified.
    	FAT_count = 0		' Default character count to 0.
    
    ' Skip over SD/MMC/FAT subroutines
    	Goto SkipSD
    
    
    ' Subroutines for communicating with an SD/MMC card
    ' Subroutine to initialize SD card pins
    InitIO:
    	SD_CS = 1		' SD card not selected.
    	SD_CS_TRIS = 0		' Output SD card chip select.
    	SD_CD_TRIS = 1		' Input card detect.
    
    	SDO = 1			' Start SPI data out high.
    	SDO_TRIS = 0		' Output SPI data out.
    	SDI_TRIS = 1		' Input SPI data in.
    	SCL = 1			' SPI clock idles high.
    	SCL_TRIS = 0		' Output SPI clock.
    	Return
    
    
    ' Subroutine to initialize hardware SSP for SPI at less than 400kHz
    OpenSPIM:
    	If (SDC_UseHardSPI) Then
    		SSPSTAT = %00000000	' Sample at middle of data output time, Mode 1, 1: Transmit on idle to active clock transition.
    		SSPCON1 = %00010010	' SPI master mode, clock = Fosc/64, Mode 1, 1: Clock idle high.
    		SSPEN = 1		' Enable hardware SPI port.
    	Endif
    	Return
    
    
    ' Subroutine to initialize hardware SSP for SPI at full speed
    OpenSPIMFast:
    	If (SDC_UseHardSPI) Then
    		SSPSTAT = %00000000	' Sample at middle of data output time, Mode 1, 1: Transmit on idle to active clock transition.
    		SSPCON1 = %00010000	' SPI master mode, clock = Fosc/64, Mode 1, 1: Clock idle high.
    		SSPEN = 1		' Enable hardware SPI port.
    	Endif
    	Return
    
    
    ' Subroutine to release hardware SSP from SPI
    CloseSPIM:
    	If (SDC_UseHardSPI) Then
    		SSPEN = 0		' Disable hardware SPI port.
    	Endif
    	Return
    But not really sure what to do? Hope anyone can help out...

    /tacbanon

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    Hi,
    I've never used that code but I'd probably try SDC_UseHardwareSPI = FALSE.
    However, don't change the SDFS.pbp file. INCLUDE it in your program and ADD SDC_UseHardwareSPI = FALSE after including it (see the example) - it will "overwrite" the default setting.

    /Henrik.

  8. #8
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    Hi Henrik,
    Thanks for the response, I will try it and post here my result.

    Kind regards,
    tacbanon

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    /Henrik is correct.

    This example may help.
    http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING
    I did comment out the pin alias in SDFS so I could change things around in my code without bothering with opening the include.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Question on SPI Data out on PortC.7(pic18f4550)

    @Dave
    Sorry for the late reply...thanks for the link..got it to work now.

    /tacbanon

Members who have read this thread : 1

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

Posting Permissions

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