BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mikemeaney
 
Posts: 11
Joined: Fri Sep 13, 2013 3:29 pm

BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

Post by mikemeaney »

Hey,

I'm looking for some insight on why the BlueFruit LE isn't playing well with other devices on my SPI bus. I'm working on a project that's loosely based on the GuggenHat tutorial (AMAZING TUTORIAL BTW). I'm taking a different spin on it, in that I've written my own iPhone app to send commands to the the Arduino Micro that is powering the NeoPixels.

---The Problem---
During iOS testing it's become apparent that the 2.5k of SRAM on the Arduino Micro may not be enough for my ambitions. So I picked up a few 32KB SPI SRAM ICs from Microchip (23A256). Using the standard SPI library and the hardware SPI (via a Logic Level converter) port on the Micro I can read/write from/to the SPI SRAM no problem, wicked fast.

But when I add the BlueFruit LE Module, the only values that get read in from the SRAM are all 0xFF using SPI.transfer().

---What I've tried---
I tried to programmatically pull the Bluefruit Request and Reset lines high and low (all combinations of each) hoping that that Bluefruit's Chip-Select was active the same time as the SRAM's and data was colliding on the bus. (I don't have a scope or logic analyzer to see these things)

---What I need---
A reason why the the Bluefruit LE and SRAM IC work just fine separate of each other, but when combined the only thing
I can read and write from on the SPI bus is the Bluefruit LE. What workarounds can I use? Put the SRAM on arbitrary pins and bit-bang data using ShiftOut()? How much slower would that be? Or should I consider just giving up on basing my design on the Micro, even though It has everything I need except for way more RAM.

BTW, this is a wearable project, so smallness and power efficiency are key!

Thanks,

Mike M.

Thanks

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

Post by adafruit_support_mike »

Check the datasheets for your SRAM chips and see what mode of SPI they support.

There's no official standard for SPI, so everyone is free to chose a set of signals that are generally SPI-like and run with them. The nature of the data and clock signals leads to four possible ways of interpreting the signal stream, called modes 0-3.

The Arduino and all our SPI hardware use mode-1, but a lot of memory chips use modes 0-2. That puts the devices at odds with each other over what the signals mean, and chaos ensues.

Uber-geek Paul Stoffregen (creator of the Teensy) has been doing some work with SPI transactions (setting the mode for a specific data transfer in a way that doesn't confuse any of the devices), but it's still in the testing phase. He's recently posted a library that might help:

http://forums.adafruit.com/viewtopic.ph ... ns#p320861

The other solution is to use a couple of other pins and do a software SPI connection. It isn't as fast, but that may not be a major problem if your BT bit rate is fairly low.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

Post by paulstoffregen »

mikemeaney wrote:I'm looking for some insight on why the BlueFruit LE isn't playing well with other devices on my SPI bus.
I've been working to solve these SPI conflicts.

Yesterday, I posted a new version of Adafruit_nRF8001 and SPI, which are in need of testing and feedback. If you're able to carefully replace files and you can help test (and post complete code to reproduce whatever problems you discover), please join in and help. We really need more people to test this new version, to figure out it if truly is 100% effective at solving these conflicts.

http://forum.pjrc.com/threads/27069-Ada ... #post58371

Updating Adafruit_nRF8001 is only half of the issue. You'll also need to add SPI.beginTransaction(settings) and SPI.endTransaction() to your code for that Microchip SRAM. These new functions tell the SPI library to protect your SPI usage. If a Bluetooth packet arrives after you've used SPI.beginTransaction(), the SPI library will prevent the nRF8001 from disrupting your communication with the SRAM. Right after you call SPI.endTransaction(), the SPI become available again to the nRF8001.

At least, that's how it's supposed to work. If you're willing to try new "bleeding edge" code, please grab the new SPI and Adafruit_nRF8001 from that page, and add SPI.beginTransaction() & SPI.endTransaction() to your own code for the SRAM. Detailed documentation on these new functions can be found here:

http://www.pjrc.com/teensy/td_libs_SPI.html

I've put a *LOT* of work into solving these SPI issues over the last several months. This stuff is getting merged into the latest versions of official Arduino. But I can't possibly test everything, so I'm really depending on feedback from people like you, who've hit these issues in real projects.


If you really want to know more technical details about how SPI transactions, here's a blog I wrote about it some time ago...

http://www.dorkbotpdx.org/blog/paul/spi ... in_arduino

User avatar
mikemeaney
 
Posts: 11
Joined: Fri Sep 13, 2013 3:29 pm

Re: BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

Post by mikemeaney »

Wow, thanks Paul and Mike

I'll take a look at these files once I get my hardware reassembled. I took this roadblock as an opputurtnity to make my design more hackable for testing proofs of concept without dismantling it. (Clumsy me punctured the brand new Li-Poly battery in the process (doh!). I should be up and running again by the end of Sunday and I'll give those files a shot then and let u know how they worked out.

-Mike M.

User avatar
mikemeaney
 
Posts: 11
Joined: Fri Sep 13, 2013 3:29 pm

Re: BlueFruit LE & SPI SRAM. A Battle on the SPI bus.

Post by mikemeaney »

So far so good. All of Sunday wound up being a Hardware day (Oh IDC connectors, how I love and hate thee) making my design more "I wanna test an Idea" friendly.

I've got the libs from repo working independently just fine. I even created a copy of the Arduino app (renamed "Arduino Test SPI") and that's were I'm working on using Paul's SPI library seeing that I trashed the contained SPI files and replaced them with his.

I did a "break-it" test so far with my SRAM test sketch that just reads from address 0x00 to 0x7FFF and writes random 8 bit values to them. I created a SPI settings object, implemented the SPI.beginTransaction() and SPI.endTransaction() functions. When working with MODE0, it works fine. In MODE1, it behaves just the same way that it was when used in conjunction with the BLE module.

I'm on the trail....

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”