• AVR Freaks

18F2525 SPI SD Card and Petite FatFS

Author
MitYeltu
Senior Member
  • Total Posts : 127
  • Reward points : 0
  • Joined: 2010/02/02 12:05:03
  • Location: TN
  • Status: offline
2016/02/22 08:17:36 (permalink)
0

18F2525 SPI SD Card and Petite FatFS

I am starting a new project and need some guidance.
The new project will involve data logging to an SD Card. I have done SD datalogging in the past, but using a different compiler. I am using XC8 v1.35 on MPLABX v3.05 and programming to 18F2525. I read somewhere that the old libraries created for c18 (I think) will not work with XC8. I found in researching this that the FatFs is apparently very good and will allegedly port over easily to the PIC18 series.
 
Here is where things might get a little hairy. In addition to the SD card that will be using the SPI protocol, I also need to poll several thermocouples that will be using MAX6675 chips for data acquisition and communications. The problem I have with the current compiler I am using is that I can't use the SD Card protocol AND the SPI protocol at the same time. Because of this, I have had to separate the 2 functions on 2 separate PICs and then have the 2 communicationg via UART. Not ideal.
 
I understand that the FatFs system (even the petite version) may not fit on the currently selected 18F2525. This is not an issue as I can get a different chip; however, I need to stay with the 18F series, so I can't go the pic24 or pic32 to get the nifty PPS functionality.
 
My question, for those who have done this (or something similar) before: If I use the FatFs for the SD card datalogging, can I still use the SPI module to grab the data from the thermocouples without a conflict?
#1
bosco
Super Member
  • Total Posts : 2119
  • Reward points : 0
  • Joined: 2004/07/24 10:17:53
  • Location: Idaho
  • Status: offline
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/22 13:08:27 (permalink)
0 (1)
There are some 18F that have two SPI peripherals.
The all the MAX6675 can share one SPI peripheral by having individual chip selects (another IO pin per each) enabling only one MAX6675 chip select at a time. 
 
#2
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11432
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/22 13:46:10 (permalink)
0 (1)
An SD card can share an SPI bus, as long as all devices have a chip select line.
 
I'm not sure that Petit FatFS will work for data logging since it appears to be effectively read-only.  The full FatFS is ~20KB on a PIC18, so you shouldn't have an issue fitting it into your PIC assuming you're using the commercial compiler.
#3
NKurzman
A Guy on the Net
  • Total Posts : 18053
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/22 19:38:41 (permalink)
0 (1)
"but using a different compiler."  Which?
I read somewhere that the old libraries created for c18 (I think) will not work with XC8.  Part of the Periperial Libraries where ported to XC8, The are EOL now, but still can be downloaded.
C18 can still be used if you need that.
It is You Code you can share the SPI Bus. Each item will need its own chip select.
OR you can Bit Bang an SPI, not that hard.
OR choose a PIC with two SPI Ports.
 
"can I still use the SPI module to grab the data from the thermocouples without a conflict?"
You need to manage the conflict.  This is a SW problem, not a HW one.
 
#4
MitYeltu
Senior Member
  • Total Posts : 127
  • Reward points : 0
  • Joined: 2010/02/02 12:05:03
  • Location: TN
  • Status: offline
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/24 10:17:30 (permalink)
0
@NKurzman: I have been using Oshonsoft Picbasic Compiler. It works great! I really do enjoy using it. It comes packaged with a simulator that is the best on the market as far as I'm concerned. I know that if it runs on the simulator it will run on the chip (provided I wire it up right).
The problem is 2-fold. There is no 16/32 bit compiler - and I want to start using those - and the SD Card library (which works great) conflicts with the SPI module (like I said before).
I've bit-banged SPI while using the hardware SPI module (which may not actaully be bit-banging), but never on other IO pins. I understand the protocol, but to get the synchronous transfer of data of non-dedicated pins seems pretty difficult to this little brain of mine. I can see all kinds of problems, but I'll take a look around for that.
 
@bosco: I'll have to look into the other PICs (that is a really good idea if I can implement it), but I suspect the oschonsoft compiler won't handle them - just a hunch. If so, I'll be right back in the same boat. Plus, I really would like to use C to program the thing.
 
Thanks for the help.
#5
NKurzman
A Guy on the Net
  • Total Posts : 18053
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/24 11:01:58 (permalink)
0 (1)
Assuming the Library is written in such a way (Poorly) that nothing else can use that SPI bus.
 
Bit-Banging simply mean controlling the port pin via software.  Look at the timing diagram for the MAX6675
set the pin high, add some NOPs set it low, read the pin and shift, same with the output.
It is the simplest thing to bit bang.
 
Note: Newer PIC18s have More Memory, More SPI Ports and PPS, and will most likely cost less.
the PIC18F2525 data sheet was last update 2008
#6
MitYeltu
Senior Member
  • Total Posts : 127
  • Reward points : 0
  • Joined: 2010/02/02 12:05:03
  • Location: TN
  • Status: offline
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/25 09:41:09 (permalink)
0
Yeah, and I'd like to use the newer chips, but the oshonsoft compiler I'm currently using is limited. It does not support the newer chips. I'll try the bitbanging thing. I've never done that, but SPI is about as simple a protocol as it gets, so it can't be that hard.... right? 'Specially since you've already given me the pseudocode.
 
Thanks.
#7
Danno
Super Member
  • Total Posts : 273
  • Reward points : 0
  • Joined: 2005/09/07 10:12:10
  • Status: offline
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/25 15:25:56 (permalink)
0 (1)
As JTemples suggests petite FS is effectively read only.  It has a write, but it can only rewrite a pre-existing file.  It cannot add a new file to the directory, nor can it extend an existing file.  Is that a limitation you can live with?  I used pFS but only for read and I had a most everything turned off.  It compiled to about 6KB.  I haven't tried FatFS but I'm happy to learn it only builds to about 20KB (Thx JT).
 
As far as a newer part to use, take a look at the PIC18F26K20.  It is a much newer device with two SPI ports and it's about half the price of the PIC18F2525.
#8
NKurzman
A Guy on the Net
  • Total Posts : 18053
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: 18F2525 SPI SD Card and Petite FatFS 2016/02/25 17:27:46 (permalink)
0
The Key to Bit Banging SPI is phase.
Do you write after the Clock goes High to Low , Or after the Clock goes Low to High.
The Same for reading.
 
The Data sheet for the Slave should have the details.
#9
Jump to:
© 2019 APG vNext Commercial Version 4.5