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