Modifications

Sauter à la navigation Sauter à la recherche
116 octets ajoutés ,  26 février 2022 à 00:22
Ligne 230 : Ligne 230 :     
=== SPI Bus ===
 
=== SPI Bus ===
An SPI bus is high speed full duplex bus. High speed means several mega-hertz (can be up to +20 MHz). The full duplex means communicates in both direction at the same time.  
+
An SPI bus is high speed full duplex bus.  
 +
* High speed means several mega-hertz (can be up to +20 MHz).  
 +
* Full duplex means communicates in both direction at the same time.  
   −
SPI bus are very short (below 10cm) and use 3 wires for the data bus + a "Slave Select" wire per device:
+
Thanks to its high throughput, the SPI bus are used for display, data acquisition, data transmission, etc.
    +
SPI bus are short (below 10cm) and uses '''3 wires for the data bus + a "Slave Select" wire per device''':
 +
* MOSI: Master Out Slave In. Communication from the microcontroler to the device.
 +
* MISO: Master In Slave Out. Communication from the device to the microcontroler.
 +
* SCLK: Clock signal giving the rythme to the data transfer.
 +
* SS: Slave Select (activated at LOW) used to activate the device on the bus. It is also used to start "transaction" with the device.
   −
bus is a very popular serial bus in electronic to connect sensors and electronics to a microcontroler. Some DIY Maker companies did also use some "normalized" connectors around I2C bus. You may probably already ear words about Qwiic from SparkFun, StemmaQt from Adafruit (Qwiic compatible), Grove from SeeedStudio.
+
The following snip of code creates an instance of the SPI(0) bus
 +
<syntaxhighlight lang="python">
 +
from machine import Pin, SPI
   −
Maybe not the fastest bus, this bus is easy to wire and to manage and requires only 2 wires:
+
ss = Pin( 5, Pin.OUT, value=1 ) # Slave Select in deactivated state by default.
 
+
spi = SPI( 0, baudrate=400000 ) # reducing clock speed to 400 KHz
    SDA: Serial Data
+
</syntaxhighlight>
    SCL: Serial Clock
  −
 
  −
The I2C protocol use an address (0..127) to contact the target board with request and waiting for response. For sure each sensor boards must have an unique address on the I2C. On I2C implementation, the microcontroler do always keeps the control over the I2C communication.
     −
<syntaxhighlight lang="python">
+
{{underline|Tips & Tricks:}}<br />Under MicroPython the SS pin is not "hardware" tied to a given SPI bus. User can freely choose which pin to use as "Slave Select".
from machine import Pin
  −
x
  −
x
  −
x
  −
x
  −
</syntaxhighlight>
      
== Additional tutorials ==
 
== Additional tutorials ==
29 917

modifications

Menu de navigation