diff options
| author | Abel Tim <abel@main.home> | 2024-06-02 17:57:32 +0200 |
|---|---|---|
| committer | Abel Tim <abel@main.home> | 2024-06-02 17:57:32 +0200 |
| commit | 6671a64563369d8e3540639753ba64086a75d7a3 (patch) | |
| tree | 7bb8a4dc198773c517ac2148e7e051be1f76aaba /spi_comm/openmv_slave/spi_com_master.py | |
| parent | b6bdab63c9902604a74a7b4b996bdd0dc7614454 (diff) | |
| download | robotica-6671a64563369d8e3540639753ba64086a75d7a3.tar.gz robotica-6671a64563369d8e3540639753ba64086a75d7a3.zip | |
add files
Diffstat (limited to 'spi_comm/openmv_slave/spi_com_master.py')
| -rw-r--r-- | spi_comm/openmv_slave/spi_com_master.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spi_comm/openmv_slave/spi_com_master.py b/spi_comm/openmv_slave/spi_com_master.py new file mode 100644 index 0000000..6e10881 --- /dev/null +++ b/spi_comm/openmv_slave/spi_com_master.py @@ -0,0 +1,36 @@ +from machine import SPI, Pin +deg = 40 +binary = format(deg, 'b') +print(binary) + +spi = SPI(0, baudrate=400000) # Create SPI peripheral 0 at frequency of 400kHz. + # Depending on the use case, extra parameters may be required + # to select the bus characteristics and/or pins to use. +cs = Pin(4, mode=Pin.OUT, value=1) # Create chip-select on pin 4. + +try: + cs(0) # Select peripheral. + spi.write(b"12345678") # Write 8 bytes, and don't care about received data. +finally: + cs(1) # Deselect peripheral. + +try: + cs(0) # Select peripheral. + rxdata = spi.read(8, 0x42) # Read 8 bytes while writing 0x42 for each byte. +finally: + cs(1) # Deselect peripheral. + +rxdata = bytearray(8) +try: + cs(0) # Select peripheral. + spi.readinto(rxdata, 0x42) # Read 8 bytes inplace while writing 0x42 for each byte. +finally: + cs(1) # Deselect peripheral. + +txdata = b"12345678" +rxdata = bytearray(len(txdata)) +try: + cs(0) # Select peripheral. + spi.write_readinto(txdata, rxdata) # Simultaneously write and read bytes. +finally: + cs(1) # Deselect peripheral. |
