Hardware Reference
In-Depth Information
Table 10-11. PORTB Register with SPI Pins
PB7
PB6
PB5
PB4
PB3
PB2
PB1
PB0
Uno
SCK
MISO
MOSI
SS
Mega
MISO
MOSI
SCK
SS
Table 10-12. Arduino SPI Pin Reference
Uno
Mega
SS
PB2
Pin 10
PB0
Pin 53
MOSI
PB3
Pin 11
PB2
Pin 51
MISO
PB4
Pin 12
PB3
Pin 50
SCK
PB5
Pin 13
PB1
Pin 52
The final step is to find all references to the PORT, PIN, and DDR registers in the Arduino code. When addressing
the entire register, be mindful of the pins not used for SPI. These values should be left unchanged and should be masked
accordingly. Commonly used values may be simpler to declare globally as a constant so that only one value needs to be
changed when converting code. It is also a good idea to adopt code conventions that include thorough commenting.
This is especially important when writing registers and using bitwise operations as it can greatly simplify debugging.
Physical Best Practices
These are just a few design considerations when designing the physical layer. When working within an electrically
noisy environment, interference on the transmission lines may cause corrupted data. Wire lengths and PCB
connection tracks should be kept to a minimum; this reduces the “electrical size” of the transmission lines, limiting
the amount of interference induced into the system. This will also prevent high impedance and capacitance on the
lines from causing problems, though on a high-quality line, it is possible to get as much as 6 feet out of a transmission
line. Remember that all SPI lines that are electrically connected should have lengths totaled.
Shielding is the next consideration and especially simple to implement when using external transmission lines.
Since connected SPI devices should use a common ground, adding shielding to a transmission line is as simple as
using a shielded cable and connectors, and then running the ground through the shielding. On a board, a grounded
metal shield or ground plane can be used to keep electromagnetic radiation out. This is likely only a concern when
placing a board near large radiation sources. In less noisy environments, ribbon cable is a great choice. In most
circumstances this will be adequate and has several advantages. Ribbon cable is cheaper than shielded cable. It also
gives you the ability to add crimp connectors anywhere along the cable with no special tools.
Branches of a transmission line may be different lengths; however, the line lengths should be the same or at least
kept close. This means the MISO line should be the same length as the SCK line, which should be the same as the
MOSI line. A difference of a couple inches won't significantly impact a transmission line, even at the highest speed
available on the Arduino.
Summary
There are many was to connect chips together, and this chapter only focused on a small area of multiprocessing
communication methods. It introduced SPI and SABB, which utilize the fastest communication available on the
Arduino, allowing you to create more complex projects and devices.
 
 
Search WWH ::




Custom Search