[En-Nut-Discussion] SPI Bus

Harald Kipp harald.kipp at egnite.de
Thu Jul 23 11:22:00 CEST 2009


Allister Mannion wrote:

> The codec and MP3 examples look a bit hardware device driver specific.
> I'm sort of imagining a serial type interface, but I guess (and have
> read) it's a little more complex. Maybe writing a driver like that for
> the codec would make the application code more generic/readable, but I
> was hoping I could do the whole SPI interaction as an application (i.e.
> touch nothing in the *-bld/OS folder). 

The MMC MP3 Player and the Flash MP3 Player sample

 http://www.ethernut.de/nutwiki/Flash_MP3_Player
 http://www.ethernut.de/nutwiki/MMC_MP3_Player

are quite generic in that sense, that any hardware specific code is done
in the initialization. Access to the codec is via stdio. This is the
most advanced solution, but requires a device specific Nut/OS driver.

You can always directly access the AVR hardware. Actually, before the
Nut/OS SPI bus driver has been available, this was used by all drivers
of SPI devices. For example

 nut/arch/avr/dev/spiflash.c

Check the function SpiByte().

The advantages of the SPI bus driver are

- SPI devices can be attached to any SPI bus, even bit-banged.
- Several SPI drivers can be attached to the same bus.

This makes its usage a bit more complicated.


> I think I'm going to have to study the nutwiki/SPI document more; from
> what you've forwarded and I've read, it looks like the closest I'm going
> to get to an example.

 http://www.ethernut.de/en/documents/ntn-6_spi.html

is the most important document. The chapter "Using the SPI bus / Low
level bus access" provides an example, that doesn't require a driver. It
should work on all platforms, because it is a bit banging driver. To use
the AVR SPI hardware, simply replace the bus driver, using spiBus0Avr
instead of spiBus0Gpio.

Harald



More information about the En-Nut-Discussion mailing list