Need object - talking to DAC / ADCs using machine code
Bits
Posts: 414
I am talking to an assortment of DACs and ADCs using spin, but the speed is now lacking. I was wondering if there is an object that is written in machine code to allow me to gather data from these devices?
Comments
Here the code I am running at the moment in spin.
This is my code attempt using the machine code object.
Can you see what I am doing wrong?
You'll also have to check the parameters to Start are OK - the clock delay and state - might need to read through the code to see what they mean (or vary them till it works!)
Thanks fellas.
My nRF24L01+ Nordic transceiver object (listed in second post of my index) uses a SPI driver without the delays. I can't recall how fast it is but I'm pretty sure it's at least twice as fast as using Beau's SPI driver (I think it's more like four times as fast).
Beau's driver also includes some other features that slow it down like setting the pin numbers with each call to a method.
Many of the chip specific SPI drivers in the OBEX (that use PASM for SPI communication) don't have these same delays and should be fast right out of the box.
You can use the same object to read several devices. You'd just need to make sure two different cogs called the object at the same time (I'm not sure what would happen, but I think one of the calls wouldn't receive the correct data).
Using it for multiple devices is where Beau's object shines, since you assign pin numbers as part of the call you can use the same object with a bunch of different devices.
There are a few SPI devices that require data being written at the same time as they are read. Beau's object does do full-duplex SPI (reading and writing with the same clock pulses). I haven't used any SPI devices that have needed a full-duplex driver but I know other forum members have.
The nRF24L01+ uses duplex SPI, BTW (the status is returned on every access). I think, IIRC, that some bits in the status register are cleared when you do an explicit read of the status register, but when the status is returned simultaneous to every command this clearing doesn't happen.
Back to DACs/ADCs - some of these devices (successive approximation ADCs) specifically require a slow-enough SPI clock to function correctly, note (the popular MCP3204/8 family being one case). So be careful not to overoptimize the clock speed without checking the datasheet!
Yes, but you can get by without it. I decided it wasn't worth the bother of trying to read it while writing.
The nRF24L01+ datasheet says you're supposed to write a $FF whenever you read from it. Just setting the MOSI high while you read does the trick, but I don't think it would really matter (in this particular case) if you wrote all zeros or something else.
Someone on the forum had a device that required duplex SPI, it wasn't just an option. I don't recall the details.
I think Beau added the variable delay to his SPI driver to allow it to be adjusted to the various clock speeds SPI devices use.