Check SPI driver for Raspberry PI B+

The Serial Peripheral Interface (SPI) bus is a synchronous serial communication interface specification used for short distance communication, primarily in embedded system. The interface was developed by Motorola.

In latest trends,for development purpose Raspberry pi becomes most acceptable platform.

Many sensors can communicate with raspberry pi using spi protocol.

For doing experiment with SPI protocol,first of all we need to check that spi master river  for raspberry pi is working properly or not.

Below given idea about how to check spi driver for Raspberry pi model B+:

Enable SPI driver:

  •  There are many ways to enable Master spi driver.Here i’m giving one of them for example.
  •  Login into Raspberry pi  using putty via ssh.
  • After successfully log in,enter command “sudo raspi-config.

raspi-config

  • In that go to Advance Options. Raspi-config-enable-spi
  •  Select SPI.raspi_config_spi_03
  • Now It shows dialogue box for rebooting board.press select to reboot.
  • After reboot you can check using lsmod command.It shows spi driver.

Now Check SPI driver:

  • First of  all check pinout for Raspberry pi mode B+.Chek which pins are used for SPI.rpi_model_b_plus_io_pinouts
  • Here for spi driver testing consider PIN19(SPI MOSI) and PIN21(SPI MISO).
  • Sort that two pins(pins 19 and 21)using wire properly.Make sure about pin numbers.
  • This condition is Loopback test for spi driver.
  • Download application code from :
    wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c
  • In raspberry pi terminal,run command :
    gcc -o spidev_test spidev_test.c
  • That make executable file spidev_test.In /dev/ due to  spi  driver we are having two device related to spi.(/dev/spidev0.0 and /dev/spidev0.1).
  • Run executable with /dev/spidev0.0.With -D argument and after that device name.As below:
    ./spidev_test -D /dev/spidev0.0
  • On failure it gives 0 in all output at receiving array in code.If failure occurs first check connections.
  • But On successful running of driver output will be as below:
    spi mode: 0
    bits per word: 8
    max speed: 500000 Hz (500 KHz)
    
    FF FF FF FF FF FF
    40 00 00 00 00 95
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    DE AD BE EF BA AD
    F0 0D
  • Now your spi driver is ready to use. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s