diff options
Diffstat (limited to 'docs/library/pyb.I2C.rst')
-rw-r--r-- | docs/library/pyb.I2C.rst | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/docs/library/pyb.I2C.rst b/docs/library/pyb.I2C.rst index 56b036e074..f60b506861 100644 --- a/docs/library/pyb.I2C.rst +++ b/docs/library/pyb.I2C.rst @@ -14,11 +14,11 @@ Example:: from pyb import I2C - i2c = I2C(1) # create on bus 1 - i2c = I2C(1, I2C.MASTER) # create and init as a master - i2c.init(I2C.MASTER, baudrate=20000) # init as a master - i2c.init(I2C.SLAVE, addr=0x42) # init as a slave with given address - i2c.deinit() # turn off the peripheral + i2c = I2C(1) # create on bus 1 + i2c = I2C(1, I2C.CONTROLLER) # create and init as a controller + i2c.init(I2C.CONTROLLER, baudrate=20000) # init as a controller + i2c.init(I2C.PERIPHERAL, addr=0x42) # init as a peripheral with given address + i2c.deinit() # turn off the I2C unit Printing the i2c object gives you information about its configuration. @@ -37,21 +37,21 @@ You can specify a timeout (in ms):: i2c.send(b'123', timeout=2000) # timeout after 2 seconds -A master must specify the recipient's address:: +A controller must specify the recipient's address:: - i2c.init(I2C.MASTER) - i2c.send('123', 0x42) # send 3 bytes to slave with address 0x42 + i2c.init(I2C.CONTROLLER) + i2c.send('123', 0x42) # send 3 bytes to peripheral with address 0x42 i2c.send(b'456', addr=0x42) # keyword for address Master also has other methods:: - i2c.is_ready(0x42) # check if slave 0x42 is ready - i2c.scan() # scan for slaves on the bus, returning + i2c.is_ready(0x42) # check if peripheral 0x42 is ready + i2c.scan() # scan for peripherals on the bus, returning # a list of valid addresses - i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of slave 0x42, - # starting at address 2 in the slave - i2c.mem_write('abc', 0x42, 2, timeout=1000) # write 'abc' (3 bytes) to memory of slave 0x42 - # starting at address 2 in the slave, timeout after 1 second + i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of peripheral 0x42, + # starting at address 2 in the peripheral + i2c.mem_write('abc', 0x42, 2, timeout=1000) # write 'abc' (3 bytes) to memory of peripheral 0x42 + # starting at address 2 in the peripheral, timeout after 1 second Constructors ------------ @@ -88,9 +88,9 @@ Methods Initialise the I2C bus with the given parameters: - - ``mode`` must be either ``I2C.MASTER`` or ``I2C.SLAVE`` - - ``addr`` is the 7-bit address (only sensible for a slave) - - ``baudrate`` is the SCL clock rate (only sensible for a master) + - ``mode`` must be either ``I2C.CONTROLLER`` or ``I2C.PERIPHERAL`` + - ``addr`` is the 7-bit address (only sensible for a peripheral) + - ``baudrate`` is the SCL clock rate (only sensible for a controller) - ``gencall`` is whether to support general call mode - ``dma`` is whether to allow the use of DMA for the I2C transfers (note that DMA transfers have more precise timing but currently do not handle bus @@ -98,7 +98,7 @@ Methods .. method:: I2C.is_ready(addr) - Check if an I2C device responds to the given address. Only valid when in master mode. + Check if an I2C device responds to the given address. Only valid when in controller mode. .. method:: I2C.mem_read(data, addr, memaddr, *, timeout=5000, addr_size=8) @@ -111,7 +111,7 @@ Methods - ``addr_size`` selects width of memaddr: 8 or 16 bits Returns the read data. - This is only valid in master mode. + This is only valid in controller mode. .. method:: I2C.mem_write(data, addr, memaddr, *, timeout=5000, addr_size=8) @@ -124,7 +124,7 @@ Methods - ``addr_size`` selects width of memaddr: 8 or 16 bits Returns ``None``. - This is only valid in master mode. + This is only valid in controller mode. .. method:: I2C.recv(recv, addr=0x00, *, timeout=5000) @@ -132,7 +132,7 @@ Methods - ``recv`` can be an integer, which is the number of bytes to receive, or a mutable buffer, which will be filled with received bytes - - ``addr`` is the address to receive from (only required in master mode) + - ``addr`` is the address to receive from (only required in controller mode) - ``timeout`` is the timeout in milliseconds to wait for the receive Return value: if ``recv`` is an integer then a new buffer of the bytes received, @@ -143,7 +143,7 @@ Methods Send data on the bus: - ``send`` is the data to send (an integer to send, or a buffer object) - - ``addr`` is the address to send to (only required in master mode) + - ``addr`` is the address to send to (only required in controller mode) - ``timeout`` is the timeout in milliseconds to wait for the send Return value: ``None``. @@ -151,15 +151,15 @@ Methods .. method:: I2C.scan() Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond. - Only valid when in master mode. + Only valid when in controller mode. Constants --------- -.. data:: I2C.MASTER +.. data:: I2C.CONTROLLER - for initialising the bus to master mode + for initialising the bus to controller mode -.. data:: I2C.SLAVE +.. data:: I2C.PERIPHERAL - for initialising the bus to slave mode + for initialising the bus to peripheral mode |