Hi all,
This is my first question here, so please bear with me on this. I am trying to get an example for reading noninteger number of bytes of data from SPI. I am aware that an "SPI.transfer(0x00)" call, reads an 8 bit data. But, for example, I don't know how to read an 18 bit data. If anyone can explain this to me with an example, I will be indebted. Thank you very much.
Assuming you are using AVR, it can only transfer in multiples of 8 bits. On other platforms, you might be able to set the size between 1-16 bits.
However, depending on the peripheral, you may be able to do a longer transfer and throw away unused bits. Otherwise, I think you have to do a bitbang SPI.
It might help if you provide a link to the datasheet for the device you are using.
Sound like an SSI device, not SPI. Post a link to the data sheet.
Welcome to the forum
As far as I know you will need to read 3 bytes of data (24 bits) because the smallest unit of data that can be transferred is an 8 bit byte
You could, of course, assign each of your 18 bits of data to a byte, transfer 18 bytes and decode it back into bits on the receiver, but that would be very wasteful
What exactly are you trying to do ?
What does the 18 bits of data represent and how is it held on the device that you are reading from ?
Incidentally, your topic title is wrong because 18 is itself an integer
It is an ADC and it is supposed to communicate with SPI. It just happens to have this sort of weird number of bits output.
Thank you very much UKHeliBob. In my topic I meant that number of bits is not integer divisible to 8. Therefore their retrieval is not done by calling "SPI.transfer(0x00)" some integer times. About the problem, this is an ADC producing 18 bits of data readable via SPI. To be more precise, it produces 8 channel data sequentially and all of them are 18bits. I am trying to read these data using SPI.
Then you would read 3 bytes and ignore the irrelevant bits.
Thanks bobcousins. Yes, I am using AVR. I also don't know how to bit bang. There is this link for product specs; https://www.analog.com/media/en/technical-documentation/data-sheets/ad7606c-18.pdf
This Arduino AD7606 library might be worth trying, at least to get started.
A web search for "arduino ad7606 spi" turns up lots of posts.
Thank you jremington for the link. I am looking at it now. It is just that all these devices in the link are 16 bits.
The device you chose does not appear to be supported by any standard Arduino libraries, so you can expect a number of challenging technical difficulties in putting it into service.
Please don't get me wrong. I am not complaining. I have done SPI work before. I know it can get complicated easily. My real issue is to understand how 18 bits read can be done. Somehow, I didn't even see an example code anywhere until now. Your suggestion is doing some kind of bit banging like "bobcousins" were suggesting before. I will work on it with the hope that it will give me an idea to solve my problem.
Do you have a breakout PCB with all the required decoupling capacitors? If so, please post a link to it.
Your very best friend is the device data sheet. Study the I/O timing diagrams and specifications for serial mode data transfer very carefully.
Fair warning: this is a horribly complicated chip, and since forum members probably won't have an example to test, you may not be able to count on much help with the details.
That sounds very much like 18 bytes of data to me
Read 18 bytes, put them in an array and decypher the values on the Arduino. How is the data arranged in the 18 bits ?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.