Jump to content

Recommended Posts



I'm trying to use an old stellaris launchpad board as a datalogger to an SD card for logging data from an accelerometer. I've already built such a project on the arduino hardware but best I can do is one reading per 2ms and I want to get it logging faster... at least 1 reading every 500us. So I thought I would port it onto the the launchpad boards I had kicking around.


Straight up the SD card didn't work trying to use SPI(3) as the underlying SPI bus and I have downloaded and tried about 6 different sd card libraries but got nowhere.


What I then did was go back to first principles. Confirm SPI is working on the default SPI bus SPI(2) before switching to SPI3 and before putting the SD libraries on top of it.


So I grabbed the simplest SPI product I had, a microchip MCP4251 digital pot and wired it up on a breadboard and confirmed it fully working at 5v with the arduino. The MCP4251 is specced for 3.3v @10Mhz so presumably there should be no issue using it with the launchpad.


When I wired it to the launchpad it didn't work. It sort of worked for one of the digital pot's channels but not for the other. It's sort of stuck on power up settings but the behaviour is not logical so I cannot diagnose a problem.


I tried the clock divider to slow it down a bit to check if that was the case but to no effect. I tried setting the SPI modes to 0 and 1 as per the pots datasheet and I tried manually pulling down the CS earlier but it seems that the SPI library does something that disables access to the CS pin.


Checking and comparing the signals at the chip with a scope they all "appear" correct but I only have a 2 channel scope and no logic analyser so I cannot check it with enough detail to confirm. I can bit bang it but want to do it in hardware. I swapped the pot for 2 others I have and they all perform (or don't perform) exactly the same. There's some sonsistency there at least.


At this stage i'm left with wondering if there's an issue with the energia SPI library. Not something I would have expected to be the case as SPI is pretty basic functionality but you never know. Alternatively it's possibly an issue with using the library. Unfortunately there are no examples of SPI usage which are relevant as they all use the msp430.


If anyone has an example that they can confirm working against a Microchip product It would be much appreciated.


I'm using energia given i'm trying to port arduino code but happy to use CCS which i've used for other projects. I'm at work and don't have the code with me which is why I havent posted code.




Link to post
Share on other sites

I have determined the exact problem.


The fact that the library is taking control of the CS pin is what caused the problem. After the first 8 bits were sent the energia library was toggling the CS pin and resetting the communication stream before sending the next 8 bits.


Looking at the SPI library code again and noting the observed behaviour I can see that the library is utterly useless in that it restricts people to a single 8bit command. Even reads would not be possible as you need to send your command then keep clocking for the response.


In fact I just realised it has no read capability at all. No wonder no one can get the SD card libraries to work when the library it relies on is so bad. :rolleyes:


At least I know what I need to do. I just need to figure our how to do it. :)

Link to post
Share on other sites


A few words about your problem:

1) since you need a sd-card example, maybe the best way is to download the Tiva package from TI - there is an example which run on CCS (and i suggest to move to CCS, since the Energia does not have a debugger, AFAIK). The sd-card configuration starts by sending some data at the rate of 400KHz, in SPI mode 0, toggling CS on every byte. Then after that, when the communication is established, the frequency is changed to 12MHz.

2) since you  made some test on another device type (and function) - many devices uses mode 0 and mode 3 or mode 1 and mode 3, so you can check also the SPI MODE 3, which is recognised to keep CS low until you finish sending a burst of data. Keep in mind you need to read each data after sending one - this is SPI nature, there are two synchronous shifting register under the same clock, connected  as a ring, so two data are moved at once.

Link to post
Share on other sites

Thanks for the feedback.

I've since spent a few hours reading the datasheet and going over the library.


The datasheet states that it does support keeping the cs low for more than one byte if the phase bit is 1. Hardware SPI can send 8 words from a loaded fifo buffer and can presumably keep sending them continuously if you can keep loading the buffer.


The energia library on the otherhand is hardcoded to send 8 bits only and read 8 bits only and that's it. Setting the phase bit has no effect on the disfunction of the spi library. Tough luck if you want to access a all 4 channels in one hit on a quad digital pot.


I'll dig deeper to see if I can establish some compatibility between the arduino and energia spi libraries. I'll use try and use CCS for this project but I'd like to be able to just jump in and knock something up quickly in energia like I can with the arduino and not have to worry about ported code not working.


Thanks for the information about how the SD cards initialise.


I've downloaded the TIVA software from here http://www.ti.com/tool/sw-tm4c?DCMP=tivac-series&HQS=tivaware I'm hoping that's what you were referring to.

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.

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...