Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

micropython-rp2040

  • Clone with SSH
  • Clone with HTTPS
  • Rob Hart's avatar
    Rob Hart authored
    c6aa16b7
    History
    Name Last commit Last update
    code
    img
    README.md

    MicroPython-RP2040

    Getting started

    Notes on Micropython for RP2040.

    Using xiao board.

    Using PyCharm Micropython plugin. Instructions here. This works well.

    Quick reference for R2040 on Micropython site.

    Nice examples for output, PWM, and ADC.

    SPI in MicroPython for adxl343 from Digikey

    Pins on the adxl343 correspont to pins on the RP2040: SCL = SCK P2, clock SDA = MOSI P3, master TX SDO = MISO P4, (Slave data out) Master RX CS = Chip Select. P1

    This works, using alternate SPI0 pins. Note that for each of two hardware SPI, there are three pin configs.

    For representation of acceleration, check adxl343 datasheet

    According to the datasheet protocol, a read is done by

    • CS low
    • Send register address, with bit 7 high for read, bit 6 optionally high for multiple bytes.
    • Read n bytes.
    • CS high. (deassert).

    In this program, data is read sequentially from six registers, using the SPI.read(n) function. The sequential register reading is described on p13 of the adxl343 datasheet. It requires setting the sixth bit of the register address high: "To read or write multiple bytes in a single transmission, the multiple-byte bit, located after the R/W bit in the first byte transfer (MB in Figure 27 to Figure 29), must be set. After the register addressing and the first byte of data, each subsequent set of clock pulses (eight clock pulses) causes the ADXL343 to point to the next register for a read or write. This shifting continues until the clock pulses cease and CS is deasserted."

    For diagram of the sequential reading of registers to get the six bytes needed for x,y, and z:

    23K256 memory chip as an example of SPI

    Datasheet for 23K256:

    Set Polarity equal to zero for this chip. This is the level of the idle clock. See SPI spec for MicroPython