Version 1.0
This package is a freely available open source package under the "Berkeley" license, same as Tcl. You can do virtually anything you like with it, such as modifying it, redistributing it, and selling it either in whole or in part. See the file "license.terms" for complete information.
tclspi was written by Karl Lehenbauer.
Install prerequisites, configure, build and install...
sudo apt-get install tcl8.6-dev libi2c-dev autoconf
autoconf
./configure --with-tcl=/usr/lib/tcl8.6
make
sudo make install
The Raspberry PI is equipped with one SPI bus that has two chip selects.
The SPI master driver is disabled by default on Raspbian. The enable it, use raspi-config or ensure the line dtparam-spi-on isn't commented out in /boot/config.txt and reboot. If the SPI driver was loaded you should see the device /dev/spidev0.0. This information taken from https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
To enable SPI using raspi-config:
- sudo raspi-config
- select option 5, interfacing options
- select option P4 SPI
- It says "Would you like the SPI interface to be enabled?", select Yes.
- raspi-config will say "The SPI interface is enabled"
- select Finish in raspi-config
- execute sudo reboot
After rebooting and logging back in, an "ls /dev/spi*" from a shell should show /dev/spidev0.0 and /dev/spidev0.1. If is says /dev/spi* not found then you didn't successfully get the SPI interface enabled.
The user pi has permissions to access the spi device, as does the superuser. To grant permission to other users, edit /etc/group and add the user names to the line beginning with spi, comma-separated. After permissions have changed the user must log out and log back in before the new permissions take effect.
package require spi
package require spi
set spi [spi #auto /dev/spidev0.0]
$spi read_mode 0
$spi write_mode 0
$spi write_bits_word 8
$spi read_bits_word 8
$spi write_maxspeed 500000
$spi read_maxspeed 500000
set transmitString "heya_kids_heya_heya_heya"
set receiveString [$spi transfer $transmitString 50]
puts "sent: $transmitString"
puts "recd: $receiveString"
$spi delete
Makefile.in
Makefile template. The configure script uses this file to
produce the final Makefile.
README
This file
aclocal.m4
Generated file. Do not edit. Autoconf uses this as input
when generating the final configure script. See "tcl.m4"
below.
configure
Generated file. Do not edit. This must be regenerated
anytime configure.in or tclconfig/tcl.m4 changes.
configure.in
Configure script template. Autoconf uses this file as input
to produce the final configure script.
generic/tclspi.c
SPI interface routines.
generic/tclspi.h
include file
generic/tclspitcl.c
Init routines.
tclconfig/
This directory contains various template files that build
the configure script. They should not need modification.
install-sh
Program used for copying binaries and script files
to their install locations.
tcl.m4
Collection of Tcl autoconf macros. Included by
aclocal.m4 to define SC_* macros.
Building under most UNIX systems is easy, just run the configure script and then run make.
$ cd tclspi
$ ./configure
$ make
$ make install
tclspi has not been built under Windows at this time.
The recommended method to build extensions under Windows is to use the Msys + Mingw build process. This provides a Unix-style build while generating native Windows binaries. Using the Msys + Mingw build tools means that you can use the same configure script as per the Unix build to create a Makefile.
If you have VC++, then you may wish to use the files in the win subdirectory and build the extension using just VC++.
Instructions for using the VC++ makefile are written in the first part of the Makefile.vc file.
make install
tclspi installs like so:
$exec_prefix
/ \
lib bin
| |
PACKAGEx.y (dependent .dll files on Windows)
|
pkgIndex.tcl (.so|.dll files)
The main .so|.dll
library file gets installed in the versioned PACKAGE
directory, which is OK on all platforms because it will be directly referenced with by 'load' in the pkgIndex.tcl
file. Dependent DLL files on Windows must go in the bin directory (or other directory on the user's PATH) in order for them to be found.
tclspi has not been tested with Windows so none of the above may be true.