SPI and gadgeteer

i have a project i`m starting to work on that require the use of SPI, not used it befre as such a couple of questions have come up that maybe someone can help clarify for me.

As i understand it using the built in SPI classes i can sent 8 bits or 16 bits in one burst out from the MOSI, however what i need todo is send 24bits out under one burst. the reason for this is the device i what to talk to has 24bit input shift register. 8 bits indicating the data register to access and 16 bits being the actual data to write.

Looking at a S type gadgeteer port the MOSI, MISO and SCK signals are obvious. It is regarding the chip select CS pin that i have confusion. i need to keep a signal low for the whole 24 bits of data to be clocked into the slave device so do i use the CS pin for this or a GPIO pin?

direct from the chip manual “The write sequence begins with a falling edge of the SYNC signal; data is clocked in on the SDIN data line on the falling edge of SCLK. On the rising edge of SYNC, the 24 bits of data are latched; the data is transferred to the addressed register and the programmed function is executed (either a change in DAC output or mode of operation).”

in summary to sync the data to the SPI device do i use the CS pin or a GPIO pin from a S type socket. i can`t try this at the moment as it is the basis from a new module im designing

thanks for your time

I would try using GPIO pin to have full control of the CS.

thanks architect, this was the conclusion i came to as well.

As a general note then i assume most spi devices only have frames of 8 or 16 bits and the the CS flag would take care of latching the data. is this automatically taken care of by the underlying driver ?

i`m also wondering that if you have more than one device on a SPI network and they all require CS flags then general IO pins need to be used as there is only one dedicated CS pin on a s type gadgeteer port, kinda makes me wonder why bother having a dedicated CS pin on this type of port at all ?

Turns out if i read the api properly, :slight_smile:

" The Microwire/SPI interface is a synchronous serial communications protocol in which multiple devices can be connected with one another by means of a single three-wire system. This three-wire system includes the serial data in signal, the serial data out signal, and the serial clock. You must use an additional GPIO pin as a chip select for each device that will communicate on the Microwire/SPI interface.

There are both 8-bit and 16-bit modes of operation using the overloaded read and write methods that have byte (8-bit) arguments or unsigned short (16-bit) arguments. Note that you can configure both 8-bit and 16-bit devices and have them share the SPI interface"

Also note that, when using the built in CS pin of NETMF, then CS will go low for three bytes if the buffer you write contains three bytes. It is really easier than people make it out to be. Ignore the whole 8bit/16bit thing.

ah, thanks gmod. it all starts to become clear now, the funny thing is if i didnt read into spi and got myself confused, and just got on with it i wouldnt have had any problems, oh well at least i have some better understanding now.