Oliviers-OSS / libmpsse

Automatically exported from code.google.com/p/libmpsse
0 stars 0 forks source link

Cannot send only 4 bits of data in SPI mode #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I try to communicate with the MCP3202 A/D converter. This converter from 
Microchip has an SPI interface and, according to the documentation, at the 
begginning of communication I've to send 4 bits to the A/D in order to select 
the input analog channel, set the bit-ordering mode, etc. After sending these 4 
bits, subsequential 13 clock cycles will output a null bit and the 12 bits of 
the converted value.

So, using the "write" function is not an option because as far as I know this 
function sends only a byte at a time, and I must write only 4 bits to the chip, 
not an entire byte. Is there any way to do so with libmpsse? or I've to modify 
it?

For the sake of reference, this A/D chip is part of a DLP-2232DAQ board. I've 
managed yet to communicate with the I/O ports included there thanks your great 
libmpsse, so thank you for your work!

Original issue reported on code.google.com by masores...@gmail.com on 5 Mar 2013 at 3:21

GoogleCodeExporter commented 9 years ago
Currently libmpsse only supports sending 8-bit bytes, although adding support 
for arbitrary bit-length transfers shouldn't be hard since the FTDI chips do 
support that. I'll put it on the todo list, but in the meantime yes, you will 
either need to modify libmpsse, or bitbang the data using libmpsse's bitbang 
mode.

Original comment by heffne...@gmail.com on 11 Mar 2013 at 2:14

GoogleCodeExporter commented 9 years ago
I've checked in some patches to the trunk that now include WriteBits and 
ReadBits functions. Initial testing seems OK, but I need to test them on a real 
device.

Original comment by heffne...@gmail.com on 22 Mar 2013 at 7:07

GoogleCodeExporter commented 9 years ago
The latest code from the trunk contains two new functions: ReadBits and 
WriteBits, which allow you to read and write from 1 to 8 bits at a time. They 
can be safely mixed with the Read and Write functions in your code. I have 
tested this at different bit widths in SPI0 mode reading and writing data MSB 
first.

Original comment by heffne...@gmail.com on 25 Mar 2013 at 3:00