2 spi, Interface examples, Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual
Page 39: 1 spi, Loopback test utility

KTD-S0057-I
Page 35 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
10.2 SPI
TM
Interface Examples
10.2.1 SPI
TM
Loopback Test Utility
A simple way to check the SPI
TM
interface consists in shorting of the data lines (MISO, MOSI). After that you
can use the following program with root rights (compiled on Ubuntu
TM
distribution):
/*
* SPI testing utility (using spidev driver)
* Copyright (c) 2007 MontaVista Software, Inc.
* Copyright (c) 2007 Anton Vorontsov
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/
#include
#include
#include
#include
#include
#include
#include
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static const char *device = "/dev/spidev3.0";
/* Connector J2105 pin 5 to 8 */
/****** Do not forget to enable SPI3 (= spidev4.0) in U-Boot Setup ******/
/*static const char *device = "/dev/spidev4.0";*/
/* Connector J2105 pin 23 to 26 */
static uint8_t mode = 0;
static uint8_t bits
= 8;
static uint32_t speed = 1000000;
static uint16_t delay;
static void pabort (const char *s)
{
perror
(s);
abort
();
}
static void transfer (int fd)
{
int
ret;
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, 0xDE, 0xAD,
0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D };