Difference between revisions of "SPI"
m (→Linux user space C code) |
(→Linux configuration) |
||
Line 16: | Line 16: | ||
== Linux configuration == | == Linux configuration == | ||
− | SPI is used by some kernel | + | SPI is used by some kernel drivers, then selecting them will naturally activate the corresponding SPI. To use the SPI from user space you have to unsure that correct SPI is selected in «make linux-menuconfig»: |
<pre class="config"> | <pre class="config"> | ||
Line 40: | Line 40: | ||
</pre> | </pre> | ||
− | + | When loaded ("''modprobe spidev''"), this driver will create a ''/dev/spidev2.0'' node to read/write on spi from userspace. | |
− | By default, ''spidev device'' | + | By default, on [[APF27Dev]], ''spidev device'' uses the bus number 2 (spi2.0) and PortB17 as chip select. To change this (for expert), the structure ''spi_board_info'' must be modified in platform file apf27-dev.c (in directory ''buildroot/output/build/linux-2.6.29.6/arch/arm/mach-mx2/'') : |
<source lang="C"> | <source lang="C"> | ||
Line 56: | Line 56: | ||
}, | }, | ||
#endif /* CONFIG_SPI_SPIDEV */ | #endif /* CONFIG_SPI_SPIDEV */ | ||
+ | ... | ||
+ | #ifdef CONFIG_SPI_SPIDEV | ||
+ | #define SPIDEV_CS (GPIO_PORTB | 17) | ||
+ | ... | ||
</source> | </source> | ||
Revision as of 09:44, 10 April 2012
Page under construction... Informations on this page are not guaranteed !!
This page will summarize the informations to use the SPI bus on our boards.
Overview
SPI (Serial Peripheral Interface) is a 4-wire full-duplex serial bus. Wires used in SPI are :
- MOSI, Master Output Slave Input : send data to slave.
- MISO, Master Input Slave Output : receive data from slave.
- SCLK, : Serial Clock signal used to synchronise the transmission. (In imx27 (apf27) maximum frequency of SCLK is 22.167MHz in master mode and 16.625 in slave mode.
- SSx, Slave Select : used to select the slave for communication with master.
On APF27, the i.MX27 contains 3 SPI devices that can be configured in master (slave is not supported by linux). APF9328 (i.MXL) contains 2 SPI.
Linux configuration
SPI is used by some kernel drivers, then selecting them will naturally activate the corresponding SPI. To use the SPI from user space you have to unsure that correct SPI is selected in «make linux-menuconfig»:
Device Drivers ---> [*] SPI support ---> ... <*> Freescale iMX SPI controller [*] CSPI1 [*] CSPI2 [*] CSPI3 ...
And special user device (spidev) option must be selected too :
Device Drivers ---> [*] SPI support ---> ... *** SPI Protocol Masters *** <M> User mode SPI device driver support ...
When loaded ("modprobe spidev"), this driver will create a /dev/spidev2.0 node to read/write on spi from userspace.
By default, on APF27Dev, spidev device uses the bus number 2 (spi2.0) and PortB17 as chip select. To change this (for expert), the structure spi_board_info must be modified in platform file apf27-dev.c (in directory buildroot/output/build/linux-2.6.29.6/arch/arm/mach-mx2/) :
#ifdef CONFIG_SPI_SPIDEV
{
.modalias = "spidev",
.controller_data = &spidev_hw, /* for chip select */
.max_speed_hz = 8000000, /* 8MHz */
.bus_num = 1, /* SPI2 */
.mode = SPI_MODE_1,
.chip_select = 2,
.platform_data = &apf27_spidev_config,
},
#endif /* CONFIG_SPI_SPIDEV */
...
#ifdef CONFIG_SPI_SPIDEV
#define SPIDEV_CS (GPIO_PORTB | 17)
...
For more details on spidev usage, see kernel documentation.
Linux user space C code
To write/read on SPI via spidev driver, use ioctl as described in spidev documentation. To simplify it, a simple library named as_spi has been written for ARMadeus Project.