PDA

View Full Version : Question on SPI Data out on PortC.7(pic18f4550)



tacbanon
- 10th September 2012, 14:33
The following code is working...


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

pedja089
- 10th September 2012, 15:09
Yes, if you are using software SPI. Then you can put SD pin's on almost any pin on PIC.

tacbanon
- 10th September 2012, 23:54
@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

mackrackit
- 11th September 2012, 00:16
If you are using the SDFS from MeLabs it is built in.

tacbanon
- 11th September 2012, 01:28
Hello macrackit, I will check it out..thanks.

Kind regards,
tacbanon

tacbanon
- 11th September 2012, 04:12
I'm trying to figure it out this block of code from SDFS how to make disable hardware SPI.


' 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

HenrikOlsson
- 11th September 2012, 06:28
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.

tacbanon
- 11th September 2012, 08:00
Hi Henrik,
Thanks for the response, I will try it and post here my result.

Kind regards,
tacbanon

mackrackit
- 11th September 2012, 08:23
/Henrik is correct.

This example may help.
http://www.picbasic.co.uk/forum/content.php?r=272-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.

tacbanon
- 15th September 2012, 02:29
@Dave
Sorry for the late reply...thanks for the link..got it to work now.

/tacbanon