This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI expansion on the AM335x EVM-SK?

Hello,

I've been searching for a tutorial on accessing the SPI on J11 of the Starter Kit.  The HW docs show it as mapped to SPI0 CS0.  Using Linux how does one configure/read/write to it?

This is my first exposure to Linux, so my questions are probably naive.  I've searched the /dev/ directory and there is no SPI0.0 accessible.  In /sys/, buried deep are some references to mcspi, but I'm unclear as how to get to them.

Thank you for your help...

  • Biser,

    Thank you for the links.  They look like they will be quite helpful.  It answers some other questions I had about how the beaglebone remapped the pins depending on which cape was attached.

    Now on to see if I can get the SPI/Zigbee port working on the EVM-SK

    James

  • James,

    Be sure to update everyone with your progress here. You aren't the only person looking for this!

    Thanks,

    Jason Reeder

  • Okay, I think I have it working.  I'm a complete noob so what I've done may be crude and violate some unwritten laws...


    Enable spidev in the kernel source for the AM335xEVM-SK

    Derived from the "SPI on the Beaglebone using SPIDEV"

    http://communistcode.co.uk/blog/blogPost.php?blogPostID=1



    Change to the arch/arm/configs directory

    Edit am335x_evm_defconfig

    Change the "CONFIG_SPI_SPIDEV" to yes:

    #
    # SPI Protocol Masters
    #
    # CONFIG_SPI_SPIDEV is not set
    CONFIG_SPI_SPIDEV=y



    Change to arch/arm/mach-omap2

    Edit board-am335xevm.c

    Modify the structure  am335x_spi0_slave_info to:

    static struct spi_board_info am335x_spi0_slave_info[] = {
        {
            .modalias      = "spidev",
            .max_speed_hz  = 24000000,
            .bus_num       = 1,
            .chip_select   = 0,
            .mode           = SPI_MODE_1,
        },
    };



    Add "{spi0_init, DEV_ON_BASEBOARD, PROFILE_ALL}," to the structure evm_sk_dev_cfg :

    /* EVM - Starter Kit */
    static struct evm_dev_cfg evm_sk_dev_cfg[] = {
        {mmc1_wl12xx_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {mmc0_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {rgmii1_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {rgmii2_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {lcdc_init,     DEV_ON_BASEBOARD, PROFILE_ALL},
        {enable_ecap2,     DEV_ON_BASEBOARD, PROFILE_ALL},
        {tsc_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {gpio_keys_init,  DEV_ON_BASEBOARD, PROFILE_ALL},
        {gpio_led_init,  DEV_ON_BASEBOARD, PROFILE_ALL},
        {lis331dlh_init, DEV_ON_BASEBOARD, PROFILE_ALL},
        {mcasp1_init,   DEV_ON_BASEBOARD, PROFILE_ALL},
        {uart1_wl12xx_init, DEV_ON_BASEBOARD, PROFILE_ALL},
        {wl12xx_init,       DEV_ON_BASEBOARD, PROFILE_ALL},
        {gpio_ddr_vtt_enb_init,    DEV_ON_BASEBOARD, PROFILE_ALL},
        {spi0_init, DEV_ON_BASEBOARD, PROFILE_ALL},
        {NULL, 0, 0},
    };



    Follow the instuctions in the processor wiki to recompile the kernel

    http://processors.wiki.ti.com/index.php/AMSDK_Linux_User%27s_Guide


    Clean the kernel sources:

    make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- mrproper


    Set the configuration:

    make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- am335x_evm_defconfig


    Compile the kernel:

    make ARCH=arm CROSS_COMPILE=arm-arago-linux-gnueabi- uImage


    Copy uImage to the boot partition of the SD card.  You can use the existing MLO and u-boot.



    Boot the board



    Check in the /dev folder for

    spidev1.0



    Testing the SPI device


    Get a copy of spidev_test.c


    Compile spidev_test.c

    arm-arago-linux-gnueabi-gcc spidev_test.c -o spitest


    I copied the output, spitest, to /home/root directory on SD card


    Short pins 3 and 6 of the J11 (Zigbee connector).  Pin 1 is the square pad.


    Execute spidev_test

    ./spitest -D /dev/spidev1.0



    If it's working correctly you should see:

    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


    Enjoy...

  • hello

    i am doing the same process as given by you , but i am not able to find the dev/spidev. please help me . also can you give me idea how to interface LTC6804G-2 ic with our am335 borad through spi interface

  • i

    neerav parasher said:

    hello

    i am doing the same process as given by you , but i am not able to find the dev/spidev. please help me . also can you give me idea how to interface LTC6804G-2 ic with our am335 borad through spi interface

    its working i got that dev/spidev but when i run the spidev_test.c application how do i understand whether the hx data which is coming in out put is the same data coming from my spi slave device . because both the time when connecting and disconnecting  it is showing the same hx form data .

    root@am335x-evm:/# ./spitest  -D /dev/spidev1.0
    spi mode: 0
    bits per word: 8
    max speed: 500000 Hz (500 KHz)

    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF

  • Neerav,

    It looks like the MOSI is not connected to MISO.  The all "FF" condition usually indicates no data on  MISO

    A couple of ideas,

    1. Do you have a jumper (wire) across the MOSI and MISO pins?

    If you're using the EVM-SK it's J11, "Zigbee Header", pins 3 and 6.  See the schematic page 3 of 17.

    2. Do you have the pins you're using set correctly?

    Again the EVM-SK already has the pinmux work done for SPI on J11.

    Looks like you're almost there.

    James

  • hello james

    thanks for reply but i have AM335 calixto board  which is having all spi 4 pins out from the expansion connector J20 for spi0 .but i want to know since i connect the device LTC68041G-2 which takes ADC input and communicate through spi ,as i feel connection is ok but i didnt get whether the application is giving data is coming from device and if not how  do i sense data from the device .

    And this application spidev_test.c will be use full for this device ?

  • Neerav,

    spidev_test just sends out  incrementing bytes and reads them back.  

    Again, I'd suggest you put a jumper across MISO and MOSI and run the spidev_test program to verify that the port works as expected.

    Go through the code.  You can use the spidev_test as a starting point to writing your own interface code for the LTC part.  Just strip out the stuff that you don't need.

    As is, it will not do anything if you hook it up to your battery monitor part.

    You'll need to read the LTC datasheet to figure out the commands to send to the part.

    The first one is always the hardest to get working!

    Have fun...

    James