Custom Shield - MicroSD/FRAM

@kennethlimcp honestly I think there's just something wrong with his code which we need to see to continue debugging...

Does that mean i will have to call digole.begin() every time i want to write to the display, and SD.begin() each time i use the sd, and FRAM.begin() each time i read from FRAM?? see what im saying? i have 4 or 5 devices all using SPI… at the same time on the same project, each one will change the CS line as begin is called… which is not really what i want. i need to initialize the SPI MOSI and MISO and CLK for all of them… they are always the same but set my own CS for each.

Or am i getting confused and we are creating instances of the SPI class and each library has its own instance to use with its own CS line?? i dont know… its way over my head… and I’m tired…

@Hootie81, something needs to be clarified. The SPI firmware code, much like in the Arduino, does NOT control the chipselect line beyond the SPI.begin(cs) part. If you look at all your SPI device libraries, you will see that each controls its own CS line. The only thing is that when you call SPI.begin(cs) with a pin specified, it will set that pin to OUTPUT and write a HIGH to it (deselect). Not specifying a pin causes SPI.begin() to setup the A2/SS line which may not be desirable. :smile:

1 Like

Ahhh i see i see… i thought that it did the CS automatically for you when you set it with begin(), so you didn’t have to control it manually like all the libraries did.

But what your saying makes total sense! it just sets up the pin and then you control it…

Next question: Multiple devices that use different modes and speeds… whats the best practice for this? currently i call a function that sets up the mode and clock divider etc then calls SPI.begin() again.

@Hootie81, therein lies the rub. @BDub did some work on SPI and contributed some great pull requests to the firmware and here is what his conclusions were:

  • Changing SPI speed or bit order does NOT affect the SPI bus
  • Changing the SPI mode DOES affect the SPI bus and creates a ā€œburpā€ when changed.

So it seems that you can’t change the SPI mode at will without affecting the SPI bus and devices. However, I am not quite sure what the effect is if all devices are deselected when the switch occurs. Perhaps @BDub can chime in here? :stuck_out_tongue:

As long as all of your SPI devices have a CS/SS enable, you can force them all to ignore the mode change side effects by setting the CS/SS to the inactive state (typically HIGH). At the time I was working with something that didn’t have this SS feature… I think it was a 74LS595 LCD backpack or motor shield or something like that.

You can change the SPEED, BIT ORDER and MODE all without having to call BEGIN again… just note that MODE changes should be done with CS/SS lines inactive (HIGH typically).

If all of your code is Round Robin style, one access after the other… you’ll be fine just controlling everything simply with CS lines. But if you start to have multiple things accessing the SPI bus asychronously, you’ll have to create a bus arbiter much like was done recently on the Spark Core between the CC3000 and on-board SFLASH.

1 Like

@BDub, any idea why changing SPI mode with the Digole and SD at before each read/write (before the CS enable) does not seem to work?

i think i tracked this down… but i cant remember what it was

it may be ā€˜burp’ related because the CS on SD cards works slightly differently??.. i cant remember! i gave up and called begin every time!

3 things are called by begin, i remember playing with these… but didn’t get very far

card.init(SPI_FULL_SPEED, csPin) &&
Ā Ā Ā Ā Ā Ā Ā Ā  volume.init(card) &&
Ā Ā Ā Ā Ā Ā Ā Ā  root.openRoot(volume);

it made things a real PITA as i had to keep closing the file, display text and then reopen the file

Do tell me more :slight_smile: Initializing with the desired mode and each device separately works, but not switching back and forth between them at run time? Should we spinoff a new thread or offline discussion?

there was lots of chat about it in the digole display thread from about post 443

Read all that, still don’t see why calling SPI.begin() after MODE / SPEED changes is necessary to make the SD & Digole work. calling mode and speed already re-inits SPI, there’s only a few properties that are not re-initialized that don’t look like they would matter. The testing i did with on-the-fly mode, speed, bit order changes all worked… i.e., SPI.transfer(val) was sending a proper value. I didn’t have anything to read from at the time, so perhaps that’s the part that’s an issue? If you are clocking out data still, and data is on the bus when you perform a SPI read but you don’t get that value in your code, then there’s definitely a port pin or peripheral setup issue.

It’s a strange one… digole is output only and SD is bi - directional… The issue was after displaying on the digole the SD would throw an error on cmd17 off the top of my head…

I did a bit of research a while ago and I think I put it down to the way CS works on an SD

@Hootie81, @BDub it looks like we will have to do a ā€œformalā€ analysis of the issue since the SPI bus is so important. The odd device is the Digole which operates on mode 1 meaning data is clocked on the trailing (falling) edge of the SCK clock instead of the leading (rising) edge of Mode 0.

Since neither the SD or Digole libraries use interrupts to service the devices, it is safe to assume the code is running round-robin and synchronously. All this to say that SD transactions are mutually exclusive of Digole transactions. So in theory, with both devices deselected, the SPI hardware could be reconfigured without affecting the devices. As you pointed out @BDub, changing any SPI parameter re-writes the config structure out to the hardware essentially resetting it in the process. So why does calling SD.begin() before every SD transaction fix the issue but not changing the SPI mode before the low level driver where SPI.transfer() is called not work? Any thoughts?

1 Like

Nope. As you said its time to kick the butt of said SPI library and application code to figure this out. Break out the scope, data sheets, logic analyzer, pull your pants up and put your boots on.

3 Likes

I got a scope/logic analyzer the other day… should be here when i get back… woot! this is what i am getting http://www.linkinstruments.com/mso19.html

I put it down to an SD problem not an SPI problem…
here is someone else with a similar problem with a totally different system to ours and his solution

could someone try sending 2 or so 0xFF out on the SPI after changing back to the right mode/speed without any CS going asserted and then try reading data from the SD?? i read somewhere this may clear some register… i would try myself but the core is packed away… the wife wouldn’t let me bring it on holiday!

and maybe a check to see if the SD library is setting the CS high after its finished?? maybe if a file is open or due to a bug it leaves the CS low??

here is a useful link that explains the error codes that we get… under the initialization section there is a link to a flow chart.
http://elm-chan.org/docs/mmc/mmc_e.html

1 Like

Parts have arrived in Singapore and the PCB finishing looks beautiful!

PCB assembly is planned for next weekend and testing will happen immediately after. If we are able to ship next weekend, that would be awesome. :smile:

5 Likes

Thought you guys might love to hear this. :smile:

1.) Tested 1 x hand-soldered board to make sure all the PCB is routed properly. :heavy_check_mark:

2.) All the functionality of the board are tested working! :heavy_check_mark:

  • Read/Write to Both FRAM
  • List files in microSD card
  • Card Detect

3.) Populated all the 30 boards for Manufacturing Run 1 WOOOHOOOO!

Unfortunately, i have not gotten to the Testing Jig yet. It will be designed this weekend together with the FRAM library.

More to come! :smiley:

4 Likes

Here’s a preview of the Testing Jig! Powered by a Spark Core. :wink:

Here’s a Shield that passed all the tests (except uSD not tested yet)

UPDATE:

All the shields have been tested and ready for shipping :smiley:

5 Likes

@kennethlimcp huge props, man! Those look awesome–my favorite part is obviously your DIY test jig :smile:

1 Like

@will, it’s my 1st time designing a Testing Jig and I’m sure my future designs will turn out better! :smiley:

I have another feature Jig planned for an event in October so keep a look-out. :slight_smile:

1 Like