Jump to content
43oh

TM4C129 Tiva C Series + SD Card


Recommended Posts

Hey,

 

I'm trying to get my Tiva board to be able to read/write SD cards. Is there a schematic that describes the SPI connection between the board and the SD card? I've looked at the booster board schematic, and wired up the card accordingly, but I can't get it to work with neither the SD card library from the Energia github repo nor this: https://github.com/rei-vilo/SD_TM4C .

 

I tried to look at the definitions of SPI.setModule in the repo to figure out which pins are wired to which module according to the SPI library, but I don't understand which hardware directory is meant for the board I have.

 

Cheers,

Jan

Link to post
Share on other sites

I've used Booster Pack 1, and set the module number to 2, the CS pin is PC_7 and I wired it accordingly. Here's how I have wired it:

 

SD card pin -> Tiva

1 (CS) -> PC7

2 (MOSI) -> PD1

3 (GND) -> GND

4 (VCC) -> +3.3V

5 (SCK) -> PD3

6 (GND) -> GND

7 (MISO) -> PD0

Link to post
Share on other sites
  • 2 weeks later...
  • 1 year later...

This code looks very promising.  However, I am having an issue initilizing the SD Card. 

 

Jasiek's write up is quite helpful and explains why the code does not work. However, I am not able to figure out how to assign the SPI port. Where did you see the SPI port definitions?  

 

I am using the MSP430F5529 so the pin out is probably not in the code anywhere. I need to find the section that describes how to call the different version of the SPI to see what the pin out to use.   I will need to reassign the pin numbers so this code can work with the LSP430F5529.

 

Any help would be awesome.

 

Spineless

Link to post
Share on other sites

Hi,

on the energia.nu you find the documentation of your board, including the pin assignment.

As you can see, your board has two SPI "modules" - 0, the default one (pins 7, 8, 14, 15) and module 1 (pins 9, 10, 33, 34).

From the SPI library's documentation, you can see how to change the used module (setModule() function) and how to use the SPI interface.

 

Rergards,

Liviu

Link to post
Share on other sites

Yes.   I agree.  The pin number and the SPI options for the launchpad and Energia are known to me.  But how to impliment this in the SD_TM4C SD card module is the question.  Since you describe the two SPI modules as 0 and 1that would mean the code has been written to configure these two options.

 

Jasiek mentioned he had to add the number 2 to select the right SPI module to make his board work. Somewhere the number 2 is defined and this appeared to work for him...I have no idea how it worked or where this code is.

 

The code calls card.init    

 

card.init(CS_PIN, SPI_HALF_SPEED, SPI_MODULE_NUMBER);

 

He simply added the number 2 as a variable.

 

Of course this number would not neccassarily be the same number for the MSP430F5529 launchpad.  But I did attempt numbers 0 through 4 in this parameter just to see if something would happen. It did not work..... There was no indication that this actually would work since the documentation is unfinished.   (Hope to fix this now)

 

There are no parameters in the CardInfo.ino example that helps me set up the pin out or setup the SPI mode.  Why does the number 2 work for Jasiek's application on his board? On the msp430F5529  the SPI mode would be 0. But this has to be described someplace.  How would I use the number 0 to select the right SPI module? ....simply entering 0 into the varaible SPI_MODULE_NUMBER did not work.

 

Looking at the SPI description on Energia and the MSP430 datasheet has not helped.  The information is either too high level or too low level.  The MSP430F5529 software manual (SLAU2080.pdf page 972)  describes reseting USCI by a PUC or by the UCSWRST bit,  When the UCSWRST bit resets the UCRXIE, UCTXIE, UCRXIFG, UCOE, and UCFE bits.....this type of info should have already been developed someplace....like in the devise specific library of the Energia project (ideally-->Energia/hardware/MSP430/variants/launchpad_f5529/pins_energia.h).  I should not need to write this....this must be someplace already written.  Dont you think?

 

Likewise the page on Energia that describes the SPI is not detailed enough to configure the SPI option.      SPI.setModule(SSIModule);   SSIModule is not defined.  What is that?  How do I use it?

 

 

I think SPI module 0 and SPI module 1 have not been defined or called.   Either new code must be witten to define the SPI modules 0 and 1 or if it is already available it needs to be linked to the SPI_MODULE_NUMBER.   I am thinking the best appoach would be to find where the code is that controls SPI_MODULE_NUMBER and see how it is implimented.   Jasiek did it somehow.  It should be a simple thing to tweek it to work for the MSP430.  

 

 

Spineless

Link to post
Share on other sites

I have some code I can share from the cardinfo example  ( first five lines in Void setup are mine and the rest are from the example) ..... It does not compile. 

include <SPI.h>
#include <SD.h>
#include <Energia.h>

#define ss P2_7     //the slave select pin

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

Void Setup
{
  Serial.begin(9600); 
  pinMode(ss, OUTPUT);          //set slave select pin to output
  SPI.setModule(0);  
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV8);

  Serial.print("\nInitializing SD card...");

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);


  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

 
The error I get is the following:
 
/var/folders/9r/q549gvps2bs4_2b6g63nq9kr0000gn/T/arduino_modified_sketch_307694/CardInfo.ino: In function 'void setup()':
CardInfo:48: error: 'class SPIClass' has no member named 'setModule'
exit status 1
'class SPIClass' has no member named 'setModule'
Edited by bluehash
[ADMIN] Please use code tags <>.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...