Reader small image

You're reading from  Yocto for Raspberry Pi

Product typeBook
Published inJun 2016
PublisherPackt
ISBN-139781785281952
Edition1st Edition
Concepts
Right arrow
Authors (2):
TEXIER Pierre-Jean
TEXIER Pierre-Jean
author image
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

Petter Mabäcker
Petter Mabäcker
author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker

View More author details
Right arrow

Chapter 8. Diving into the Raspberry Pi's Peripherals and Yocto Recipes

In this chapter, we will learn how to handle the SPI and i2c buses of the Raspberry Pi through the Yocto Project. We'll see how to write our own recipe for custom applications.

The SPI bus


The Serial Peripheral Interface (SPI) protocol implements a synchronous serial link between a master and a slave. When a single slave is used, only three signals (and ground) are needed.

The master generates an SCLK (serial clock) clock signal, which is sent to the slave. On some transitions of this clock, the slave will read data using the appointed signal, MOSI (short for master out, slave in), or write it using the signal named MISO (master in, slave out). There are several names, depending on hardware manufacturers, used to describe these signals. It is recommended to use the MISO/MOSI notation (the most common one), because it removes any ambiguity: the MOSI pin of a master must always be connected to the MOSI pin of a slave, and the same is true for the MISO pin.

If several slaves are to be connected to the same host, they may be connected in parallel (all MISO pins connected together as well as all MOSI pins), but an additional signal (CS, or Chip Select) is required for...

The i2c bus


The i2c protocol enables us to port a master component (usually the microprocessor) and several slave devices. Several masters can share the same bus, and the same component can send slave status to the master or vice versa. However, communication takes place only between the master and one slave. Note also that the master can send a command to all slaves simultaneously (such as a sleep or reset request).

At the electrical level, the protocol uses signals alternating between high and low levels; the most common value pairs are (0, 5V) and (0, 3.3V). The SCL clock signal is generated by the master. The serial data (SDA) data signal is set high or low by the master or slave, according to the communication phase. Throughout the duration of the high segment of the SCL clock, the SDA data signal must be kept high or low, depending on whether it transmits a 1 or a 0.

Finally, as shown in the following figure, particular configurations of signals (produced by the master) can indicate...

The Wii Nunchuck


The Nunchuck has an X/Y joystick, an X/Y/Z accelerometer, and two buttons (Z and C).

The sensor data is communicated through the i2c bus.

The Nunchuck connector

The connector contains four wires, two of which are power and ground. The other wires are used for i2c communication (SDA and SCL). The following diagram demonstrates the principle:

Note

If you are worried about your  connection, you can find  an adapter for  this controller at https://www.sparkfun.com/products/9281.

The Raspberry Pi connection


For the connection with our Raspberry Pi, we just have to connect it to the main connectors, I2C1_SDA and I2C1_SCL, as shown in this pin diagram:

The Nunchuck's protocol

The Wii Nunchuck contains a controller that communicates through the i2c bus. In order to know where to store bytes written to it, the first byte must be an 8-bit register address. In other words, each write() operation to the Nunchuck requires one register address byte, followed by data bytes.

For a write operation, the first byte sent to the Nunchuck tells it where to start (the START condition).

Encryption

The Nunchuck is designed to provide a specific encrypted link. However, this can be disabled through the following process:

  • Write 0x55 to the Nunchuck's 0xF0 register

  • Pause

  • Write 0x00 to the Nunchuck's 0xFB register

Write

Pause

Write

  

0xF0

0x55

-

0xFB

0x00

Note that if you own a white Nunchuck, the process will be different:

  • Write 0x00 to the Nunchuck's 0x40 register

Summary


In this chapter, we learned how to integrate a package to test the SPI interface of the Raspberry Pi. We also learned how to create an application for the Wii Nunchuck and how to deploy it inside the Yocto Project.

In the next chapter, we will understand how to integrate a media hub with the Raspberry Pi.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Yocto for Raspberry Pi
Published in: Jun 2016Publisher: PacktISBN-13: 9781785281952
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
TEXIER Pierre-Jean

Pierre-Jean TEXIER has been an embedded Linux engineer at Amplitude Systèmes (Amplitude Systèmes was a pioneer in the marketing of Ytterbium femtosecond lasers) since 2014 where he maintains a custom system on chip i.MX6 with the Yocto project (meta-fsl-arm), which is made by a French company: EUKREA. He is a graduate of ESTEI school at Bordeaux where he spent 3 years as a student in order to become an embedded Linux Engineer. He is a big ardent of the world of free software and the embedded world. His knowledge background includes C/C++, Yocto, Linux, Bash, Kernel development but he is also open to trying new things and testing new technologies. First, I want to thank my patience wife for her during my writing sessions. I also give thanks my parents and my brother, who without them, this book possibly would not have happened. I would also like to thank all of the mentors that I've had over the years. Mentors such as Cyril SAGONERO, Sylvain LE HENAFF, Pierre BORDELAIS, Vincent POULAILLEAU, Fabrice BONNET, Jean-Claude PERESSINOTTO, Pierre AUBRY. Without learning from these teachers, there is not a chance I could be doing what I do today. To finish I would like to thanks Eric MOTTAY the CEO of Amplitude Systèmes, Luca TESTA the head of Electronics team at Amplitude Systèmes for his trust, Hitesham WOODHOO, Alexandre GAMONET, Kevin PINTO and Guillaume MACHINET For the various discussions about the raspberry pi during coffee breaks.
Read more about TEXIER Pierre-Jean

author image
Petter Mabäcker

Petter Mabcker is a senior software developer specializing in embedded Linux systems. For the past 8 years, he has been working with embedded Linux professionally. Currently, Petter works as a Scrum Master and senior software developer at Ericsson AB. Additionally, his knowledge includes C/C++, shell scripting, Yocto Project (including BitBake and OpenEmbedded), Scrum, and Git. In 2013, Petter started the small business Technux, which he runs as a side project in parallel with his duties at Ericsson. Some of the focus areas of the business are open source embedded Linux projects, such as the Yocto Project, together with different projects that involve the Raspberry Pi. As part of the work with Technux, Petter works as a contributer to the Yocto Project (including the Raspberry Pi BSP layer, known as meta-raspberrypi).
Read more about Petter Mabäcker

Write

 

0x40

0x00...