Hi
 did you get solution for this?

On Tuesday, 5 November 2013 08:00:16 UTC+5:30, Helen Paiva wrote:
>
>
> Hi all,
> I am beginner with the BeagleBone Black board and I have a problem with 
> the SPI communication.
> I am trying to communicate with the Redpine wifi board by SPI. The 
> BeagleBone Black is the master and the wifi board is the slave. 
>
> Part of the configuration of my BB-SPI0DEV-00A0.dts is the follow:
>
> /* state the resources this cape uses */
>     exclusive-use =
>         /* the pin header uses */
>         "P9.17",    /* spi0_cs0 */
>         "P9.18",    /* spi0_d1 MOSI */
>         "P9.21",    /* spi0_d0 MISO*/
>         "P9.22",    /* spi0_sclk */
>         /* the hardware ip uses */
>         "spi0";
> fragment@0 {
>         target = <&am33xx_pinmux>;
>         __overlay__ {
>             bb_spi0_pins: pinmux_bb_spi0_pins {
>                 pinctrl-single,pins = <
>                     0x150 0x10  /* spi0_sclk.spi0_sclk, OUTPUT_PULLUP | 
> MODE0 */
>                     0x154 0x30  /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 */
>                     0x158 0x10  /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 
> */
>                     0x15c 0x10  /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | 
> MODE0 */
>                 >;
>             };
>         };
>     };
>
>
> I made all the configuration for the SPI and I am trying to execute the 
> spidev_test exemple.
> I am using the osciloscophe, so I can see that the message sent and 
> received are corrects!
> I am sendding 0x15 0x00 and receiving 0x00 0x58, but in the program, the 
> receive rx only shows me 0x00 0x00.
> Somebody can help me to find what I am doing wrong? If the osciloscope 
> shows me the correct signal for the send, receive, clock and CS. What could 
> be wrong in my SPI configuration? I tried so many configurations, I dont 
> know if I am setting wrong the ioctl.
>
> Spidev_test exemplo:
>
> #include <stdint.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/spidev1.0";
> static uint8_t mode;
> static uint8_t bits = 8;
> static uint32_t speed = 500000;
> static uint16_t delay = 0;
>
> static void transfer(int fd)
> {
> int ret;
> uint8_t tx[] = {
> 0x15, 0x00,
> };
>
> 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 = delay,
> .speed_hz = speed,
> .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++) {
> if (!(ret % 6))
> puts("");
> printf("%.2X ", rx[ret]);
> }
> puts("");
> }
>
>
> int main(int argc, char *argv[])
> {
> int ret = 0;
> int fd;
>
> fd = open(device, O_RDWR);
> if (fd < 0)
> pabort("can't open device");
>
> /*
>  * 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);
>
> transfer(fd);
>
> close(fd);
>
> return ret;
> }
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to