Re: How access spi device via spi driver?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi ,
>your question is how can I access a device that dose not appear on /dev
directory.
>the answer is "mknod" command.

>reference:
>153 char    SPI Bus Interface (sometimes referred to as MicroWire)
>          0 = /dev/spi0        First SPI device on the bus
>          1 = /dev/spi1        Second SPI device on the bus
>            ...
>         15 = /dev/spi15    Sixteenth SPI device on the bus


Thanks for your reply.
I have added following into /etc/init.d/rcS

mknod /dev/spi0 c 153 0

And write some test code(See the end of this mail.)
But, I fail to open this device,  "No such device or address"
I'm trapped again. What's wrong with it???

>>
[root@arm-linux /home]# ls -al /dev/spi0
crw-r--r--    1 root     root     153,   0 Jan  1  1970 /dev/spi0
[root@utu-linux /home]# ./spi_test
: No such device or address

>>MY TEST CODE:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

int main(void)
{
 int spi_fd;

 spi_fd = open("/dev/spi0", O_RDWR);
 if (spi_fd < 0)
 {
  perror("cann't open device /dev/spi0\n");
  exit(1);
 }

 for(;;)
 {
  char str[20];
  scanf("%s",str);
  if ('1' == str[0])
   break;

  int ret = write(spi_fd, &str, sizeof str);
  if (ret <= 0)
  {
   printf("file operation error.\n");
  }

  printf("You write to spi device: %s\n", str);
 }
 close(spi_fd);
 return 0;
}
-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

[Linux ARM]     [Linux ARM MSM]     [Linux ARM Kernel]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

Add to Google Follow linuxarm on Twitter