SPI for sensor

mouha
Hi all,

Did not found out SPI code that can drive accelerometer from Linux, who
knows where to get one ?

thx

mouha
My question was not correct enough :
 I meant driving "something" with some SPI code.

gene.sally
Check out the Documentation/spi directory, there's good documentation in
there and some sample code.

Regards,
gene

mouha
thanks for your reply.
The spi code I was talking about is not the off. doc, but
about driving spi from Linux

mouha
Does anybody have SPI code >from< Linux ?

bartman
in the "firmware_bsp" dir, did you read the SPI.C file that 
begin with :


/*============================================================

  File Name: SPI.c
  Description: S3C2440A SPI controller Function Test
     Version: 0.1 

     History:
      0.1: 2003. 07. 06, Programming Start.
      0.2: 2004. 05. 14, added keyboard test codes 
                       
=============================================================*/

#include <string.h>
#include "2440addr.h"
#include "2440lib.h"
#include "spi.h"
#include "def.h"

#define spi_count 0x80
#define SPI_BUFFER _NONCACHE_STARTADDRESS

void __irq Spi_Int(void);
void __irq Dma1Tx_Int(void);
void __irq Dma1Rx_Int(void);

void Test_Spi1_MS_poll(void); // added by junon

volatile char *spiTxStr,*spiRxStr;
volatile int endSpiTx;
volatile int tx_dma1Done;
volatile int rx_dma1Done;
unsigned int spi_rGPECON,spi_rGPEDAT,spi_rGPEUP;
unsigned int spi_rGPGCON,spi_rGPGDAT,spi_rGPGUP;
unsigned int spi_rGPDCON,spi_rGPDDAT,spi_rGPDUP;

...etc

it should be the good one for you

mouga
Yes, you are right.
These are SPI tests I want to drive an external sensor (the accelerometer I
was talking, like those you have in Wii remote or Iphone) i.e. : receive
data from it, but not sure that Linux let me run a program that use
directly the I/Os .

Do you know if Linux let drive directly the SPi I/O directly from commande
line program ?

mouha
no anwsers, no one knows how to drive SPI ?

open-nandra
Working on getting some accelerometer working with SPI in linux. I'll post
a patch when will be finished. Stay tuned.

open-nandra
Attachment: patch (2.88 KB)
mouha: well this patch you can apply for mini2440 kernel from repo.or.cz.
It add to spi.0 driver for sca3000 accelerometer. If you need different
device just update board info structure. If you have any question just
lemme know at marek.belisko at gmail.com.

srikanth
hi open-nandra,
               does the patch also cover for gpio, if not can you also post
the code for gpios as well and can you give us the procedure to make the
patch.

thanks in advance,
sri.

Sergey Manucharian
Hi folks!

I gonna use SPI to communicate with several sensors/ADC/DAC. The SPI host
driver works in 2.6.32.2, and  I also have added support for the second
one, so I have spidev0.0 and spidev1.0 in /dev.

The questions arisen:

1) The driver support only 8 bit per word. Is it a hardware limitation?

2) When trying to send data (a few chars) using file writes or system calls
I get the following diagram on data/clock pins:
   __      __   __     __     __     __
__/  \____/  \_/  \___/  \___/  \___/  \___
  \__/    \__/ \__/   \__/   \__/   \__/

The "gap" between the 1st and 2nd bytes is longer and the "gap" between the
2nd and 3rd bytes is shorter than all others, which are equidistant. Also
the chip select signal is much longer than needed in case of 1-3 bytes
sent.

All the above might interfere time critical applications.

Any thoughts?
TIA

davef
My understanding is that Linux is not a real-time operating system, so use
in time critical applications MAY not be appropriate.  Search <hard real
time> and <real time Linux>.

Now, whether this is the problem is another question.

If you have other stuff going on at the same time, does SPI get priority
over those "other things"?  Is the SPI being interrupted by a higher level
task?

Can you turn off interrupts while you send all your data out?

HTH

Dave

Sergey Manucharian
I haven't researched much in that direction, but tried to set the priority
of my data sending program (by nice) to very high level, the pattern is
exactly the same all the time.

Of course, you're right about the Linux not being RTOS, but in my
particular case I wouldn't worry if I was able to send 32 bits per word. I
can't find any info regarding such a (hardware) capability.

Sushant
Hello,
I have add this line in mach-mini2440.c file for SPI inizitalization but
NODE is not created. 
#include <linux/spi/spi.h>
#include <mach/spi.h>

/* SPI devices */
static struct s3c2410_spi_info mini2440_spi0_pdata = {
        .pin_cs = S3C2410_GPG2,
        .num_cs = 1,
        .bus_num = 0,
        .gpio_setup = &s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,
};

static struct spi_board_info mini2440_spi_devs[] __initdata = {
        /* SPI device 0 */
        .modalias       = "spidev",
        .chip_select    = 0,
        .max_speed_hz   = 48 * 1000 * 1000,
        .bus_num        = 0,
};

In:
static struct platform_device *mini2440_devices[].
        &s3c_device_spi0 /* SPI bus 0 */


In:
static void __init mini2440_init(void)
        /* SPI */
        s3c_device_spi0.dev.platform_data = &mini2440_spi0_pdata;
        spi_register_board_info(mini2440_spi_devs,
ARRAY_SIZE(mini2440_spi_devs));