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
    About the element14 Community
  • 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 354 subscribers
  • Views 1730 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
Parents
  • 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
Reply
  • 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
Children
No Data
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