Loading...
Searching...
No Matches
Header buses

I2C, SPI and UART set up on the header pins. More...

Functions

 i2c (freq=100_000)
 Creates I2C object for control on the pins, SDA (D18) and SCL (D19).
 spi (baudrate=1_000_000, polarity=0, phase=0)
 Creates SPI1 object to controller the SPI bus on D13 (SCK), D11 (MOSI) and D12 (MISO).
 uart (number=0, baudrate=115200)
 Creates a UART object for use on the board header.

Detailed Description

I2C, SPI and UART set up on the header pins.

Each function returns a standard MicroPython machine.I2C, machine.SPI or machine.UART; see the MicroPython documentation for their methods.

Function Documentation

◆ i2c()

i2c ( freq = 100_000)

Creates I2C object for control on the pins, SDA (D18) and SCL (D19).

There are no pull-up resistors on the board for these pins: use a module that has them, or attach 4.7 kOhm pull-up resistors to each I2C pins. The on-board USB-PD controller is on a separate bus and never appears in scan(). Call i2c() once and keep the object.

Refer to MicroPython documentation for more information about the returned object : https://docs.micropython.org/en/latest/library/machine.I2C.html

Parameters
freqClock in Hz: 100 kHz works with almost any module; many also run at 400 kHz.
Returns
A machine.I2C.
Example
bus = mcu.i2c()
print(bus.scan())

◆ spi()

spi ( baudrate = 1_000_000,
polarity = 0,
phase = 0 )

Creates SPI1 object to controller the SPI bus on D13 (SCK), D11 (MOSI) and D12 (MISO).

This function creates an SPI1 object to allow access to the SPI internal peripheral on the RP2040. Chipselect or multiple chipselect can be any GPIO pin. The chipselect pin(s) are controlled by the user.

Refer to MicroPython documentation for more information about the returned object : https://docs.micropython.org/en/latest/library/machine.SPI.html

Parameters
baudrateClock in Hz.
polarityClock idle level, 0 or 1.
phase0 samples on the first clock edge, 1 on the second.
Returns
A machine.SPI.
Example
bus = mcu.spi()
cs = mcu.pin("D10", "out", value=1)
cs.value(0)
bus.write(b"\x01\x02")
cs.value(1)

◆ uart()

uart ( number = 0,
baudrate = 115200 )

Creates a UART object for use on the board header.

Initializes UART peripheral based on the number parameter. The only valid number are 0 and 1. The default pins for UART0 is TX = D1 and RX = D0. For UART1 the default pins are TX = D4 and RX = D5.

Refer to MicroPython documentation for more information about the returned object : https://docs.micropython.org/en/latest/library/machine.UART.html

Parameters
number0 or 1.
baudrateBits per second; both ends must match.
Returns
A machine.UART.
Exceptions
ValueErrornumber is not 0 or 1.
Example
serial = mcu.uart(0)
serial.write("hello\n") # sends on D1
print(serial.read()) # what has arrived on D0, or None