2

SPI バスを使用して max7219 8x8 LED マトリックスを使用しようとしています。

Galileo ボードで次の GPIO 設定を行いました。

デジタル ピン 機能 Linux レベル シフタ Mux ピン L: Dir_out H: dir_in
IO11 SPI MOSI spidev1.0 gpio24 gpio44(H) gpio72(L) IO12 Slave Sel 用 gpio gpio15 gpio42 -

IO13 SPI SCK spidev1.0 gpio30 gpio46(H)

上記の gpio を次のように設定しています - 必要に応じてマルチプレクサ ピンを設定します。-gpio24、gpio 42、gpio30、gpio15 をエクスポートし、方向フィールドを「OUT」、値フィールドを「0」に設定 - gpio15 (スレーブ選択値) を「0」に設定。

次のコードを使用して LED マトリックスにアクセスし、パターンを設定しています。

int fd;
uint8_t array1[2];

uint8_t array [] = {    
        0x0F, 0x00,
        0x0C, 0x01,
        0x09, 0x00,
        0x0A, 0x01,
        0x0B, 0x07,
        0x01, 0x06,
        0x02, 0x06, };

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

static uint8_t mode;
static uint8_t bits = 8;
static uint32_t speed = 50000;
static uint16_t delay;

fd= open(DEVICE,O_RDWR);
struct spi_ioc_transfer tr = 
    {
        .tx_buf = (unsigned long)array1,
        .rx_buf = 0,
        .len = ARRAY_SIZE(array1),
        .speed_hz = speed,
        .bits_per_word = bits,
        .cs_change = 1,
    };
array1[0] = array [i];
array1[1] = array [i+1];
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
            if(ret<0)
                {
                    printf("ioctl Failed\n");
                }
        usleep(500000);
        close (fd);

4

1 に答える 1

0

Galileo 1 の場合、このスクリプトを使用して spidev1.0 をセットアップできます。

#!/bin/bash -e
# v0od0ochild

echo "Configuring Spidev1.0 for Galileo.."
gpio_path=/sys/class/gpio
gpio4="out 1"
gpio42="out 0 strong"
gpio43="out 0 strong"
gpio54="out 0 strong"
gpio55="out 0 strong"
gpios="4 42 43 54 55"
setup_gpio() {
  echo "Gpio ${1}: direction: $2, value: $3, drive: $4"
  echo -n $2 > $1/direction
  echo -n $3 > $1/value
  echo -n $4 > $1/drive
}
for i in ${gpios}; do
  gpio=${gpio_path}/gpio${i}
  if [ ! -d ${gpio} ]; then
  echo "Exporting gpio ${i}"
  echo -n ${i} > ${gpio_path}/export
  fi
done
for i in ${gpios}; do
  gpio=${gpio_path}/gpio${i}
  if [ -d ${gpio} ]; then
  gpiovar=gpio${i}
  setup_gpio ${gpio} ${!gpiovar}
  fi
done
echo "Spi ready"

Galileo Gen2 を使用している場合:

#!/bin/bash -e

# v0od0ochild

echo "Configuring Spidev1.0 for Galileo-Gen2.."

#pin10
echo 26 > /sys/class/gpio/export || echo "gpio26 already exported"
echo 74 > /sys/class/gpio/export || echo "gpio74 already exported"
echo 27 > /sys/class/gpio/export || echo "gpio27 already exported"
echo low > /sys/class/gpio/gpio26/direction || echo "Failed to set gpio26 low"
echo low > /sys/class/gpio/gpio74/direction || echo "Failed to set gpio74 low"
echo in > /sys/class/gpio/gpio27/direction || echo "Failed to set gpio27 direction in"

#pin11
echo 24 > /sys/class/gpio/export || echo "gpio24 already exported"
echo 44 > /sys/class/gpio/export || echo "gpio44 already exported"
echo 72 > /sys/class/gpio/export || echo "gpio72 already exported"
echo 25 > /sys/class/gpio/export || echo "gpio25 already exported"
echo low > /sys/class/gpio/gpio24/direction || echo "Failed to set gpio24 low"
echo high > /sys/class/gpio/gpio44/direction || echo "Failed to set gpio44 high"
echo low > /sys/class/gpio/gpio72/direction || echo "Failed to set gpio72 low"
echo in > /sys/class/gpio/gpio25/direction || echo "Failed to set gpio25 direction in"

#pin12
echo 42 > /sys/class/gpio/export || echo "gpio42 already exported"
echo 43 > /sys/class/gpio/export || echo "gpio43 already exported"
echo low > /sys/class/gpio/gpio42/direction || echo "Failed to set gpio42 low"
echo in > /sys/class/gpio/gpio43/direction || echo "Failed to set gpio43 direction in"

#pin13
echo 30 > /sys/class/gpio/export || echo "gpio30 alreay exported"
echo 46 > /sys/class/gpio/export || echo "gpio46 already exported"
echo 31 > /sys/class/gpio/export || echo "gpio31 already exported"
echo low > /sys/class/gpio/gpio30/direction || "Failed to set gpio30 low"
echo high > /sys/class/gpio/gpio46/direction || "Failed to set gpio46 high"
echo in > /sys/class/gpio/gpio31/direction || "Failed to set gpio31 direction in"
echo "Spi ready"
于 2016-11-07T11:05:20.713 に答える