Hi Arthur,
BBB is a very time consuming hobby.
Take it ease, relax, go for a walk and when you return, try:
-
try your project as root
if no luck follow my (working) path
-
Try to repeat my settings and see if it works for you.
I wasn’t able to build the original Linux spidev_test, so…
What I have is:
root@beaglebone:~# uname -a
Linux beaglebone 3.8.13-bone50 #1 SMP Tue May 13 13:24:52 UTC 2014 armv7l GNU/Linux
Following the instruction from here http://www.nagavenkat.adurthi.com/2014/02/spi-communication-beaglebone-black-as-master-to-arduino-as-slave/
I created SPI-4SS-00A0.dts and compiled it into SPI-4SS-00A0.dts following exactly the instruction
By doing that you should have in /sys/devices/bone_capemgr.9/slots
0: 54:PF—
1: 55:PF—
2: 56:PF—
3: 57:PF—
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
8: ff:P-O-L Override Board Name,00A0,Override Manuf,SPI-4SS
To test it I obtained and created files in /opt/test/test2 as attached:
build
SimpleGPIO.cpp - from Derek Molloy https://github.com/derekmolloy/beaglebone/blob/master/SimpleGPIO.cpp
SimpleGPIO.h - from Derek Molloy https://github.com/derekmolloy/beaglebone/blob/master/SimpleGPIO.h
test2.cpp - mine main file
unzip attached and compile
root@beaglebone:/opt/test/test2# ./build
Building test2 - J.Sz.
root@beaglebone:/opt/test/test2#
then run (have P9-18 and P9-21 connected as loopback)
root@beaglebone:/opt/test/test2# ./test2
Initialize SS pins for SPI
Initialize SPI
SPI transfer
rx = 30 31 32 33 34 35 36 37
rx = 31 32
rx = 33 34
rx = 35 36
rx = 37 38
rx = 30 31 32 33 34 35 36 37
…
press CTRL-C to terminate or let it run and observe with a scope all SPI0 signals
Hope this will help
Jan
Sorry, I don’t see how to insert a file so:
build is:
#!/bin/bash
echo “Building test2 - J.Sz.”
g++ test2.cpp SimpleGPIO.cpp -o test2
test2.cpp is
//#ifndef SPICOMM_H_
//#define SPICOMM_H_
#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>
#include “SimpleGPIO.h”
#include
#include
#include “SimpleGPIO.h”
using namespace std;
// example functions from http://www.nagavenkat.adurthi.com/2014/02/spi-communication-beaglebone-black-as-master-to-arduino-as-slave/
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static void pabort(const char *s)
{
perror(s);
abort();
}
//4 SS pins for 4 SPI devices
void init_motor_spi_ss(int gpio1,int gpio2,int gpio3,int gpio4){
//export the pins. I have used then pins described in the table above
gpio_export(gpio1);
gpio_export(gpio2);
gpio_export(gpio3);
gpio_export(gpio4);
// set them as High. The SS pins should be high when idle(no commuication)
gpio_set_dir(gpio1, OUTPUT_PIN);
gpio_set_dir(gpio2, OUTPUT_PIN);
gpio_set_dir(gpio3, OUTPUT_PIN);
gpio_set_dir(gpio4, OUTPUT_PIN);
gpio_set_value(gpio1, HIGH);
gpio_set_value(gpio2, HIGH);
gpio_set_value(gpio3, HIGH);
gpio_set_value(gpio4, HIGH);
}
static const char *device = “/dev/spidev1.0”; // this is when SPI0 was enabled. change it when SPI1 is enabled
static uint8_t mode=0; //this mode works well for me
static uint8_t bits = 8; //arduino accepts 8 bits at once
//static uint32_t speed = 1000000; //1MHz speed
static uint32_t speed = 1000000; //2MHz speed
static uint16_t delay=0;
static void init_spi(void)
{
int fd;
int ret = 0;
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”);
}
void spi_transfer(uint8_t *txbuffer, int size, int gpio)
{
int fd;
int ret = 0;
//uint8_t tx[8];
//tx[0]=‘0’;
//tx[1]=‘1’;
//tx[2]=‘2’;
//tx[3]=‘3’;
//tx[4]=‘4’;
//tx[5]=‘5’;
//tx[6]=‘6’;
//tx[7]=‘7’;
//uint8_t rx[ARRAY_SIZE(txbuffer)] = {0, };
uint8_t rx[size];
struct spi_ioc_transfer tr = {
//tr.tx_buf = (unsigned long)tx,
//tr.rx_buf = (unsigned long)rx,
//tr.len = ARRAY_SIZE(tx),
tr.tx_buf = (unsigned long)txbuffer,
tr.rx_buf = (unsigned long)rx,
tr.len = size,
tr.delay_usecs = delay,
tr.speed_hz = speed,
tr.bits_per_word = bits,
};
fd = open(device, O_RDWR);
if (fd < 0)
pabort(“can’t open device”);
gpio_set_value(gpio, LOW);
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
pabort(“can’t send spi message”);
close(fd);
gpio_set_value(gpio, HIGH);
cout<<“rx = “;
for(int i=0;i<size;i++){
printf(”%.2X”,rx[i]);
cout<<" ";
}
cout<<endl;
}
int main(int argc, char *argv[]){
cout << “Initialize SS pins for SPI” << endl;
init_motor_spi_ss(48, 49, 60, 115);
cout << “Initialize SPI” << endl;
init_spi();
cout << “SPI transfer” << endl;
while(1)
{
spi_transfer((uint8_t *)“01234567”, 8, 48);
spi_transfer((uint8_t *)“12”, 2, 48);
spi_transfer((uint8_t *)“34”, 2, 49);
spi_transfer((uint8_t *)“56”, 2, 60);
spi_transfer((uint8_t *)“78”, 2, 115);
}
return 0;
}
THE END