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 clock signal about beaglebone(am335x)

Hi engineers,

I'm having difficulties getting the SPI clock signal to present on P9-22 in beaglebone , my image is A5, my kernel is  'Linux-3.1.0-psp04.06.00.03. SDK'.

Firstly,I  modify  the kernel file board-am335xevm.c like below:

staticstructspi_board_info bone_spi0_info[] = {
{
.modalias = "spidev",
.max_speed_hz = 48000000, //48 Mbps
.bus_num = 1,
.chip_select = 0,
.mode = SPI_MODE_0,
},
};

and

static void spi0_init(intevm_id, int profile)
{
setup_pin_mux(spi0_pin_mux);
spi_register_board_info(bone_spi0_info,
ARRAY_SIZE(bone_spi0_info));
return;
}

 Add the following to the beaglebone_dev_cfg[] struct:

{spi0_init, DEV_ON_BASEBOARD, PROFILE_NONE},

Next , I can find spidev like below :


root@am335x-evm:/# find -name 'spidev*' 
./dev/spidev1.0
./dev/.udev/names/spidev1.0
./sys/devices/platform/omap/omap2_mcspi.1/spi1.0/spidev/spidev1.0
./sys/class/spidev/spidev1.0

Then , connect pins 18 and 21 together on the P9 header.

root@am335x-evm:/mnt# ./spidev_test -D /dev/spidev2.0

spi mode: 0

bits per word: 8

max speed: 500000 Hz (500 KHz)

FF FFFFFFFFFF

40 00 00 00 00 95

FF FFFFFFFFFF

FF FFFFFFFFFF

FF FFFFFFFFFF

DE AD BE EF BA AD

F0 0D

Finally,other place I have no change in kernel and use  the default settings.

I connect beaglebone and DSP28335 together ,use the spidev_fdx.c   test,

root@am335x-evm:/mnt# ./spidev_fdx -m 3 /dev/spidev1.0

/dev/spidev1.0: spi mode 0, 8 bits per word, 48000000 Hz max

read(3, 3): 00 00 00

The default setting of related local spi is:

/* Module pin mux for SPI fash */
/*static struct pinmux_config spi0_pin_mux[] = {
{"spi0_sclk.spi0_sclk", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL
       | AM33XX_INPUT_EN},
{"spi0_d0.spi0_d0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP
       | AM33XX_INPUT_EN},
{"spi0_d1.spi0_d1", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL
       | AM33XX_INPUT_EN},
{"spi0_cs0.spi0_cs0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP
       | AM33XX_INPUT_EN},
{NULL, 0},
};

but ,I can't find spiclk signal in the pin,why?

I use an oscilloscope, spiclk signal is still low, I can't find the reason,help me ?

There are still some details need to pay attention to?


thank you !


  • HI there,

    I might not have an answer for you, however it seems like u are more advance than i am. So, i Tought i can ask u a question if it is okay.

    I have  a code that reads and writes from SPI P9 -30 and P9-29, however i need to count the clock cycles in the SPI's speed. I coudln't find anywhere what i was looking for.

    What i need is, I have a DSP that sends the signals non-stop, I need to count 7 clock cycls before i write to my SPI buffer for lenght of 21bits.

    Do you know how can do that?

    If you can help me i would appreciate, Thanks


    /*
     * SPI testing utility (using spidev driver)
     *
     * Copyright (c) 2007  MontaVista Software, Inc.
     * Copyright (c) 2007  Anton Vorontsov <avorontsov@ru.mvista.com>
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2 of the License.
     *
     * Cross-compile with cross-gcc -I/path/to/cross-kernel/include
     */

    #include <stdint.h>
    #include <string.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <getopt.h>
    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <linux/types.h>
    #include <linux/spi/spidev.h>

    #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

    static void pabort(const char *s)
    {
        perror(s);
        abort();
    }

    static const char *device = "/dev/spidev2.0";
    static uint8_t mode;
    static uint8_t bits = 8;
    static uint32_t speed = 12000000;
    static uint16_t delay;
    static uint8_t bx[27];
    static uint8_t ax[27]={0xEE};

    void transfer(int fd, uint8_t* aax)
    {
        int ret;
        uint8_t tx[sizeof ax];
        //uint8_t aax[sizeof ax];

        memcpy(tx, ax, sizeof ax);

        uint8_t rx[ARRAY_SIZE(tx)] = {0, };

        struct spi_ioc_transfer tr;
            tr.tx_buf = (unsigned long)tx;
            tr.rx_buf = (unsigned long)rx;
            tr.len = ARRAY_SIZE(tx);
            tr.delay_usecs = delay;
            tr.speed_hz = speed;
            tr.bits_per_word = bits;

        ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
        if (ret < 1)
            pabort("can't send spi message");

        for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
            bx[ret]=rx[ret];
            aax[ret]=rx[ret];
        }
        puts("");

    }

    static void print_usage(const char *prog)
    {
        printf("Usage: %s [-DsbdlHOLC3]\n", prog);
        puts("  -D --device   device to use (default /dev/spidev2.0)\n"
             "  -s --speed    max speed (Hz)\n"
             "  -d --delay    delay (usec)\n"
             "  -b --bpw      bits per word \n"
             "  -l --loop     loopback\n"
             "  -H --cpha     clock phase\n"
             "  -O --cpol     clock polarity\n"
             "  -L --lsb      least significant bit first\n"
             "  -C --cs-high  chip select active high\n"
             "  -3 --3wire    SI/SO signals shared\n");
        exit(1);
    }


    static void initialize(int fd){

            int ret = 0;

            /*
             * spi mode
             */
            ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
            if (ret == -1)
                pabort("can't set spi mode");

            ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
            if (ret == -1)
                pabort("can't get spi mode");

            /*
             * bits per word
             */
            ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
            if (ret == -1)
                pabort("can't set bits per word");

            ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
            if (ret == -1)
                pabort("can't get bits per word");

            /*
             * max speed hz
             */
            ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
            if (ret == -1)
                pabort("can't set max speed hz");

            ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
            if (ret == -1)
                pabort("can't get max speed hz");

            printf("spi mode: %d\n", mode);
            printf("bits per word: %d\n", bits);
            printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);


    }

    int main(int argc, char *argv[]){

        static uint8_t aax[27];
        //static uint8_t aaxV;
        int i=0;
        int j=0;
        int fd;


        fd = open(device, O_RDWR);
        if (fd < 0)
            pabort("can't open device");

        //aaxV =&aax[0];

        initialize(fd);

        transfer(fd, aax);

        printf("data to write\n");

        while (i<27){
            puts("");
            while (j<6 && i<27){
                printf("%.2X ", ax[i]);
                i++;
                j++;
            }
            j=0;
        }
        puts("");

            i=0;
        printf("\ndata that has been read\n");
        printf("\n AAX[] has been reading\n");
        while (i<27){
                puts("");
                while (j<6 && i<27){
                    printf("%.2X ", aax[i]);
                    i++;
                    j++;
                }
                j=0;
            }
            puts("");

        i = 0;

        while (i<27){
            puts("");
            while (j<6 && i<27){
                printf("%.2X ", bx[i]);
                i++;
                j++;
            }
            j=0;
        }
        puts("");

        close(fd);

        return 0;
    }