Sep 16, 2016 SPI.begin SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPIMODE0)); What I hadn't understood was that I first need to call SPI.begin and then SPI.beginTransaction. The above settings work with two modules, with one 74HC595 and one 74HC165 shift register each, and a two meter long ribbon cable, like this one. Thank you all for your.
Preface: This question is about a project I am working on with a professor at my university. It is NOT for a grade, but my reputation with this professor does matter. So while my success on this project is important to me, I do not see it as unfair to seek help from Stack Overflow.
That said, here is a high level overview of my project. I have an ATmega328 microcontroller. I have a Microchip SST 64 Mbit flash memory card. The ATmega has a hardware implementation of SPI. The flash memory has a hardware implementation of SPI.
My goal is to read data from and write data to the flash chip using the ATmega in SPI master mode. The memory is organized in a multiple overlay structure which is nice for erasing but for my purposes, it's basically just 32,768 pages of 256 bytes each.
To write data the basic idea is I send an instruction byte, then the starting address, then the data. To read data the basic idea is that I send an instruction byte, then the starting address, then a dummy byte, and then it starts sending me data.
So this is supposed to be a test program which programs 1 byte onto the flash and then reads it back and displays that byte on an LED array I have. If you're interested in the LED array, it can be found here: http://evilmadscience.com/tinykitlist/157
I believe my read function works because the first time I ran this, all 8 LEDs lit up. That would indicate to me that it read the flash memory when it was in it's factory state of all 1s. Now apparently I've screwed something up with the writing because the byte that lights up does not correspond at all with the byte that I'm attempting to program.
I should also note I'm using the default SPI library for Arduinos and the frame buffer functions work. When I do frame1.WriteRow(toDisp), that is working correctly and has been tested extensively.
If anyone has the time or patience to figure out what I'm doing wrong that would be extremely awesome.
EDIT: To help debugging: The LEDs are being driven by driver chips which use the SPI interface as well. I did not write that part of the code. On an oscilloscope I can see the SCK line being driven by that part of the code. However, I also have a probe on the MOSI pin and if I don't light up any lights, it never appears to go high. To me that means I'm not sending information correctly. AKA... perhaps my SPI.transfer() needs an enable function or something?
To anyone still curious the problem was that the memory chip was extremely sensitive to slow rise times. After putting in a schmitt trigger, everything worked perfectly.