I'm trying to interface with a serial connection that follows no standard (so i have to write the driver), and the only document i can find says I need a microcontroller "capable of responding to an interrupt in 2us (and repeated every 7us)"
Is this possible with the Uno?
Each byte is transmitted in a distinct burst of clock pulses, and all bits are transmitted in the first 8 pulses, starting with the most significant bit. No start bit, no end bit, I just have to capture the first 8 bits once the clock starts pulsing, but it doesn't seem like my interrupt is responding fast enough.
I should be able to sample the data line on the rising edge of the clock.
I don't see why this couldn't be done with the hardware SPI functionality - that'd be easily fast enough, and your ISR only has to handle bytes instead of bits.
DrAzzy:
I don't see why this couldn't be done with the hardware SPI functionality - that'd be easily fast enough, and your ISR only has to handle bytes instead of bits.
My understanding of SPI tells me that there would need to be a master and a slave. This doesn't have that. There's no handling of addressing or slave set or anything. I've got 2 wires only (SDA/SCK), and SPI has at least 3.
If you can direct me to a tutorial using SPI without master/slave designation, that would be great.
Believe me, I really would much rather work at the byte level, rather than the bit level.
Which arduino would be able to handle this? I ordered an Arduino 101 with the new Intel chip to see if it can handle the instructions, but i'm a little concerned about the ability to build my own board with that chip when it comes time to build this out. I'd like to cancel the order if it's not necessary.
After reading the article, it seems like the ATMega328 just isn't capable of responding fast enough, even with pin change interrupts. Based on the times he described, the code isn't being executed until after the clock pulse has already completed, and the code hasn't even finished by the time the next pulse begins. I tried them anyway, and while I got better results, my bits were still shifted to the left too far, indicating a late pickup of the data.
The device putting out the clock and the data is the master. Is the output continuous? What makes the output start and stop?
If there are gaps in the 8 bit data stream you might be able to configure a slave to read the bytes. On the receiving UNO, I think that you will need to have it set its own SS pin low. If held low, the slave should continue to read incoming bytes.
Both devices communicate to each other. The "Master" controls the clock, and sends data, but the "slave" (what i'm trying to build) needs to be able to respond by controlling the data line in sync with the clock.
So the master here sends a byte, and I need to echo that byte, and then the master will listen again for a message length byte from me, then the master sends the compliment of my length, and then I send my first message byte, and i get a compliment back, and that goes on until the end of the message. The messages can be anywhere from 2-4 bytes. IT's really just handshakes and commands. Not much information.
So as I said, this isn't really SPI because over a single data line, both devices are able to communicate.
I've ordered the Arduino 101, with the Intel Curie chip. I think, as its at least twice as fast as the UNO, it should handle my instructions easily enough. The issue is, if I get this to work, I want to package this myself on a single board. I will probably attempt to find another microcontroller that is capable, but comes in a more standard package. The Curie is by all means overkill for what I need. But it will at least let me figure out this protocol and give me proof of concept.
On an SPI bus, one device has the power to decide when to send data and can generate the clock. That is the master. In your case, it's the device you're reading from.
The Arduino is the slave, you have an ISR for the SPI interrupt (I forget whether there's more than one) that reads the SPI data register, saves it somewhere, and sets a flag to tell the rest of the sketch that it's gotten something. My read is the same as cattledog - you need to have SS held low and set input - for the slave mode to work. You might attach another pin to SS through a resistor, so you could turn that on and off, or maybe it's enough to just set it input vs output with a pulldown on it or something.
I suspect the whole thing is under a dozen lines of code on a plain old Uno/Nano/ProMini.