|
35 | 35 | //| miso_buffer[1] = (reading) & 0xFF
|
36 | 36 | //| # Send array of bytes over SPI to main
|
37 | 37 | //| device.load_packet(mosi_buffer, miso_buffer)
|
38 |
| -//| device.wait_transfer(0) |
| 38 | +//| while not device.wait_transfer(timeout=-1): |
| 39 | +//| pass |
39 | 40 | //| # Handle command from main, which sets the ADC channel
|
40 | 41 | //| selected_channel = map_adc_channel((mosi_buffer[0] << 8) | mosi_buffer[1])
|
41 | 42 | //|
|
42 | 43 | //| Communicating with the ADC emulator from the REPL of an attached CircuitPython board might look like ::
|
43 | 44 | //|
|
| 45 | +//| >>> import board |
| 46 | +//| >>> import digitalio |
44 | 47 | //| >>> import busio
|
| 48 | +//| >>> import time |
| 49 | +//| >>> |
| 50 | +//| >>> ## setup |
45 | 51 | //| >>> 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 |
46 | 55 | //| >>> spi.try_lock()
|
47 | 56 | //| 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 |
49 | 66 | //| >>> 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] |
54 | 72 | //|
|
55 | 73 | //| """
|
56 | 74 |
|
|
0 commit comments