element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet & Tria Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
ZedBoard Hardware Design spi device clock problem
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 13 replies
  • Subscribers 344 subscribers
  • Views 1608 views
  • Users 0 members are here
Related

spi device clock problem

Former Member
Former Member over 9 years ago

Hello
I am working with 7z020 board and using vivado 2015.2 version as well as petalinux 2015.2
I want to send /receive data from spi device, (in half duplex mode)for this purpose,I made the following connections.

set_property PACKAGE_PIN R19 [get_ports SPI0_MOSI_O]
set_property PACKAGE_PIN D18 [get_ports SPI0_SCLK_O]
set_property PACKAGE_PIN L21 [get_ports SPI0_SS_O]

set_property PACKAGE_PIN E21 [get_ports SPI1_MISO_I]
set_property PACKAGE_PIN L18 [get_ports SPI1_SCLK_O]
set_property PACKAGE_PIN F18 [get_ports SPI1_SS_O]

SPI1_SS_O and SPI0_SS_O is always high as I was expecting (will be low during transfer)
but cannot see clock at L18(FMC H4 pin) and D18(FMC G2 pin)
then I tried predefined softwarelike spidev_test.c i made it simple  I was trying to run the
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <signal.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 = 1;
static uint32_t speed = 18000000;
//static uint16_t delay;

static void transfer(int fd)
{
  int ret,i;
  uint8_t tx[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
          0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
          0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
          0xF0, 0x0D,
  };
  uint8_t rx[ARRAY_SIZE(tx)] = {0, };
  struct spi_ioc_transfer tr = {
    .tx_buf = (unsigned long)tx,
    .rx_buf = (unsigned long)rx,
    .len = ARRAY_SIZE(tx),
    .delay_usecs = 50,
    .speed_hz = speed,
    .bits_per_word = bits,
    .cs_change=1,
  };
  
      ret = ioctl(fd, SPI_IOC_MESSAGE(0), &tr);
              if (ret < 0)
              {
                printf("return=%d
",ret);
                pabort("can't send spi message");
              }
        printf("
receive data");
            for (ret = 0; ret < ARRAY_SIZE(tx); ret++)
            {
                if (!(ret % 6))
                puts("");
                printf("%.2X ", rx[ret]);
            }
     
}

int main(int argc, char *argv[])
{
  int ret = 0;
  //int i;
  int fd;

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

  mode = SPI_MODE_1;
  bits = 1;
  speed = 180000000;

  /*
   * 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
", mode);
  printf("bits per word: %d
", bits);
  printf("max speed: %d Hz (%d KHz)
", speed, speed/1000);
  printf("Now transfer data
");
  transfer(fd);

  close(fd);

  return ret;
}
then i got he following results
spi mode: 1
bits per word: 1
max speed: 180000000 Hz (180000 KHz)
Now transfer data

trying to transfer data

receive data data
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
where i am doing mistake? why i cant get clock?
Anyone help me
thanks in advance

  • Sign in to reply
  • Cancel
  • Former Member
    0 Former Member over 9 years ago

    Hello,

     

    Do you know that your hardware design has included the SPI controller and is working correctly? I would suggest exporting your design to the SDK and use the 'Import Examples' link available in the system.mss file to run a simple bare metal example on your hardware to make sure that works before attempting to use it at the OS level.

     

    -Gary

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Former Member

    Hello
    Did you mean SPI controllers are QSPI?? Quad SPI flash is active in my system
    I am trying to use EMIO with SPI
    Can I use spips examples??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    If you have enabled the SPI 0 and/or SPI 1 controller in your Zynq Processing System and connected to the package pins via EMIO then yes, you could us the ps_spi examples. If you look at your project in the SDK and open the system.mss file you should see a link to 'Documentation' and 'Import Examples' next to the ps7_spi controller entry.

     

    -Gary

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    For this
    I have changed the FSBL(standalone)
    and use xspips.c as standalone O/S in new application
    but i  am using petalinux so I made boot.bin with this fsbl and  generate boot.bin
    then switch on the board, boot from sd card and boot properly but
    mount /dev/mmcb0pk1 /mnt
    /mnt/xspips.elf
    it gives me illegal instruction error .
    is this error because , the sd card is not FAT32 foramtt?thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    One more thing I want to mention here for this example our constraint file look like
    set_property PACKAGE_PIN R19 [get_ports SPI0_MOSI_O]
    set_property PACKAGE_PIN E21 [get_ports SPI0_MISO_I]
    set_property PACKAGE_PIN D18 [get_ports SPI0_SCLK_O]
    set_property PACKAGE_PIN L21 [get_ports SPI0_SS_O]

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    Hello,

     

    Standalone or 'bare metal' means not using an OS at all. So no PetaLinux. That means there are no Linux type functions like 'mount'.

     

    While you could generate an FSBL and an executable .elf file and a bitstream to build a bootable .bin file to run your 'bare metal' spi code I would suggest just using the SDK to load the code via JTAG since you are just trying to test the operation of your hardware.

     

    If you are not sure how to do this you could take a look at one of the tutorials available. The most basic is probably the four tutorial set for the MicroZed ( just target the ZedBoard instead) available here: http://zedboard.org/support/design/1519/10

     

    If you have the time the Avnet Developing Zynq Software and Hardware Speedway Workshops will give you an in depth understanding of how the Zynq device and the tools work:

    http://zedboard.org/support/trainings-and-videos

     

    Adam Taylor has a really good set of blog posts that illustrate how to use the Vivado and SDK tool suite to implement a varied set of Zynq functions: http://microzed.org/content/microzed-chronicles

     

    -Gary

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    Hi
    thanks for your response. It really helping me,
    As you suggest I tried to do the same but I got the error
    Process STDIO not connected to console.
    If you'd like to see UART output in this console, please modify STDIO settings in the Run/Debug configuration.
    with the help of forum disussion i solved it and got another error
    connect STDIO to console :Jtag uart

    error opening jtag uart @ localhost-1 I was trying to solve it , the programm run and i got the following result (Idont know how it run, because again i am facing the same problem, and according to forum discussion sdk->xilinxtools->configuration of jtag I cannot find this option in sdk2015.2. any other solution?)

    http://s19.postimg.org/8q4292p2r/spi_not_working.png
    clearly shows that spiPsSelfTestExample() FAILED

    I am using picocom.
    is it my fault? or the board has some?
    In my opinion I just download the .bit file so error may be in the .bit file.
    have a look on the following pictures which shows my project

    http://s19.postimg.org/hh6hplj03/ps7_as.png

    http://s19.postimg.org/l8g2bwwoj/1_myproject.png

    http://s19.postimg.org/n1nkdz78z/2_myproject.png

    http://s19.postimg.org/px0nkub8z/3_myproject.png

    If you need to know more about my project , ask me.
    thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    Hi
    thanks for your response. It really helping me,
    As you suggest I tried to do the same but I got the error
    Process STDIO not connected to console.
    If you'd like to see UART output in this console, please modify STDIO settings in the Run/Debug configuration.
    with the help of forum disussion i solved it and got another error
    connect STDIO to console :Jtag uart

    error opening jtag uart @ localhost-1 I was trying to solve it , the programm run and i got the following result (Idont know how it run, because again i am facing the same problem, and according to forum discussion sdk->xilinxtools->configuration of jtag I cannot find this option in sdk2015.2. any other solution?)

    http://s19.postimg.org/8q4292p2r/spi_not_working.png
    clearly shows that spiPsSelfTestExample() FAILED

    I am using picocom.
    is it my fault? or the board has some?
    In my opinion I just download the .bit file so error may be in the .bit file.
    have a look on the following pictures which shows my project

    http://s19.postimg.org/hh6hplj03/ps7_as.png

    http://s19.postimg.org/l8g2bwwoj/1_myproject.png

    http://s19.postimg.org/n1nkdz78z/2_myproject.png

    http://s19.postimg.org/px0nkub8z/3_myproject.png

    If you need to know more about my project , ask me.
    thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago

    You seem to be trying to solve several problems at one time, which is always difficult. I am not sure what is causing your STDIO UART issue, but I suspect you made an error at some point in the process. I don't think you want to try to use the JTAG UART since the ZedBoard has UART1 connected to the USB UART available.

     

    I would suggest starting with a basic ZedBoard design, like the ones in the MicroZed tutorials above, and get 'hello world' working. Once you have your basic design working with UART connected to your terminal then go back and add the SPI interface to your design. The pictures you posted show that you have connected SPI0_MOSI_O to SPI0_MISO_I which does not make sense and would not work with the constraints you listed above. You should bring the MOSI and MISO signals out as well. 

     

    Once you have updated your hardware and exported the new design to the SDK then you can add the ps spi example code and see if the signals work for you.

     

    I would really suggest you spend some time going through the Speedway Workshops listed above to get a better understanding of how the system works.

     

    -Gary

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Former Member

    you are right
    I was doing the same I want to bring the MOSI and MISO but I cannot see any data (I made my own software on c). So I decided to check it with following software
    https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c
    for this i decided to connect both together so that i can see transmitted and received data.
    (I will change it again and will back to you soon)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube