Configuring the number of bits in an SPI message

I’m looking at some of the code for the Netduino and they’ve have a way of configuring the number of bits per transfer for SPI. I don’t see anything similar for the Panda II (but it’s possible I’m not looking in the right place). The device I’m playing around with requires 16 bits - how would I configure this on the Panda II?

A good place to look for answers like this is the API documentation: [url]Microsoft Learn: Build skills that open doors in your career. You can see there are two write methods, one for a byte (8 bits) and one for a uint16 (16 bits.)

@ Jeff_Birt,

Link gives 404 error:
Server Error in Application.
The resource cannot be found.

The correct link is: SPI.Write Method | Microsoft Learn
(without the dot at the end ;-))

@ paulm
actually, the LPC2387 (Panda, Panda II) can do anything between 8 and 16 bits. See the datasheet from Phillips.
But to set up the register S0SPCR correctly, you would have to use RLP, i.e. write your own SPI code (using the examples from Philips) and call it from your C# code. Doable.

Thanks, that was helpful. I was looking at SPI.Configuration and the constructor and didn’t even think of looking for an overwritten method.

It looks like Netduino code is taking advantage of the ability to set the # of bits. Luckily in my case I just needed to ensure that it was sending 16 bits. So using RLP isn’t necessary - maybe another day.

will there be some offical support for this
id like to do 12bit spi sends

netdunio has added it in 4.2.0beta1
using a class ExtendedSpiConfiguration that extends SPI.configuration

it does code like:

// use reflection to set the custom protected "BitsPerTransfer" property on our base class
            Type spiConfigurationType = typeof(SPI.Configuration);
            FieldInfo fieldInfo = spiConfigurationType.GetField("Custom_BitsPerTransfer", BindingFlags.NonPublic | BindingFlags.Instance);
            fieldInfo.SetValue(this, BitsPerTransfer);

Not needed in most applications. I personally have never seen anything that will not work with 8 or 16 bits but there maybe something out there!

Why do you need 12bits?

here is something that needs 12 bits
I am trying to get it to work with the Panda II might be a lost cause as this is very confusing

@ swestcott -

288 total bits will be 16x18. Should work with 16 bit SPI.

Chip makers normally design sensors ot work for 8bit/16bit micros anyway because many micros only support those.

Thanks I just started reading Professional’s Guide To .NET Micro Framework Application Development and it seems I did not understand SPI at all I am starting to now

@ swestcott -

I like the artwork on OctoBrite pcb. Just curious, what are building with it?

I am trying to have the LEDs change based on the sound coming from a guitar amplifier I built ( its a project in my book ) that I want to show at the MADExpo in June its a gee wiz sort of thing no piratical use and I thought it might be a good way to learn something new. I have found a driver for a chip that is almost the same that I might try to modify


Yeah, that is the chip that was used in the Tron Disc mod project.