Skip to content

Commit 00a831f

Browse files
update spitarget documentation example to be more complete and responsive
1 parent d937221 commit 00a831f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

shared-bindings/spitarget/__init__.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,40 @@
3535
//| miso_buffer[1] = (reading) & 0xFF
3636
//| # Send array of bytes over SPI to main
3737
//| device.load_packet(mosi_buffer, miso_buffer)
38-
//| device.wait_transfer(0)
38+
//| while not device.wait_transfer(timeout=-1):
39+
//| pass
3940
//| # Handle command from main, which sets the ADC channel
4041
//| selected_channel = map_adc_channel((mosi_buffer[0] << 8) | mosi_buffer[1])
4142
//|
4243
//| Communicating with the ADC emulator from the REPL of an attached CircuitPython board might look like ::
4344
//|
45+
//| >>> import board
46+
//| >>> import digitalio
4447
//| >>> import busio
48+
//| >>> import time
49+
//| >>>
50+
//| >>> ## setup
4551
//| >>> spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
52+
//| >>> cs = digitalio.DigitalInOut(board.CS)
53+
//| >>> cs.direction = digitalio.Direction.OUTPUT
54+
//| >>> cs.value = True
4655
//| >>> spi.try_lock()
4756
//| True
48-
//| >>> spi.write(bytearray([0, 0])) # ADC command: read from A0
57+
//| >>>
58+
//| >>> ## ADC command: read from A0
59+
//| >>> cs.value = False
60+
//| >>> spi.write(bytearray([0, 0]))
61+
//| >>> cs.value = True
62+
//| >>>
63+
//| >>> # wait for ADC to read a value
64+
//| >>>
65+
//| >>> ## get two-byte output from ADC
4966
//| >>> adc_result = bytearray(2)
50-
//| >>> spi.readinto(adc_result)
51-
//| >>> list(adc_result) # show output from ADC
52-
//| [196, 22]
53-
//| >>> spi.unlock()
67+
//| >>> cs.value = False
68+
//| >>> spi.readinto(adc_result, write_value=1)
69+
//| >>> cs.value = True
70+
//| >>> list(adc_result)
71+
//| [0, 255]
5472
//|
5573
//| """
5674

0 commit comments

Comments
 (0)