Launch of Linino.org
Launch of Linino.org
The communication between the main processor and the MCU can be done through the serial bus or the SPI bus. In order to leave available the serial interface active as console, you have to use the SPI bus.
Almost all of the application out of there use the serial interface to communicate with an MCU; moreover, there are tons of libraries that use the serial interface but few libraries use SPI as communication bus. For this reason, we developed a Linux SPI driver which export a TTY interface to the user space, but it implements the communication on the SPI bus. In this way you can use already existent code without any change.
To compile the SPI TTY driver you have to add it to your configuration file. You can directly add the following line to your
Or, you can use the pseudo grafical interface
make menuconfig Kernel Modules -> SPI Support enable kmod-spi-tty-ds module
Once you driver is compiled, you can load it on your device and it will appear the
ls /dev/tty* /dev/tty /dev/ttyS1 /dev/ttyS13 /dev/ttyS3 /dev/ttyS7 /dev/ttyACM0 /dev/ttyS10 /dev/ttyS14 /dev/ttyS4 /dev/ttyS8 /dev/ttyATH0 /dev/ttyS11 /dev/ttyS15 /dev/ttyS5 /dev/ttyS9 /dev/ttyS0 /dev/ttyS12 /dev/ttyS2 /dev/ttyS6 /dev/ttySPI0
Now you are able to use the
ttySPI0 interface as an usual tty/serial interface.
This Linux module has three parameters that you can use to configure the module at load time.
transfer_delay: it accepts an integer value. It configures the numer of micro-seconds to wait between two consecutive SPI transfers within the same SPI message. The default value is 25us.
transfer_len: it accepts an integer value. It configures the maximum SPI transfer lenght. This configuration depends on the MCU capabilities. The default value is 1.
max_pending_byte: it accepts an integer value. It configures the maximum number of pending bytes in the SPI controller queue. The default value is 1024.
You can also configure the module at run time thanks to sysfs attributes. You can find the following configuration attributes within the tty device in the sysfs directory
transfer_delay: it accepts an integer value. It configures the numer of micro-seconds to waits between two consecutive SPI transfer within the same SPI message. The default value is 25us. This attribute is initialized by the omonimous module parameter.
On the other side of the bus, on the MCU, there a library object that does the same job. The source library is available here.
It communicate over the SPI bus, but it appears to the system like other serial interfaces. The AVR processor with the Arduino framework this is implemented within the class
To use the
StreamSPI you have to include the SPI library:
Now you can use the pre-instanciated object
StreamSPI0 as you can use any other stream object (like
StreamSPI with the Firmata library is very easy. The Firmata library provide an initialization function that accepts a
Stream parameter. So in your code you can just write the following line and use Firmata over the SPI bus:
StreamSPI can be used also with the Bridge library, but you have to create a new instance of the
BridgeClass. Then, you must use the new instance in order to communicate on the SPI bus.
BridgeClass BridgeSPI(StreamSPI0); StreamSPI0.begin(); BridgeSPI.begin();