diff options
author | Daniel Campora <daniel@wipy.io> | 2015-08-02 20:20:03 +0200 |
---|---|---|
committer | Daniel Campora <daniel@wipy.io> | 2015-08-02 20:22:15 +0200 |
commit | c6926c374dc0408d7ef8fa6385207430c122e6cf (patch) | |
tree | 2318255e7b545b6a6756e8dce6d1ee4b87e32d10 /docs/library | |
parent | 3a2fb201a52367286d25bede4612c73b6a1cd4b9 (diff) | |
download | micropython-c6926c374dc0408d7ef8fa6385207430c122e6cf.tar.gz micropython-c6926c374dc0408d7ef8fa6385207430c122e6cf.zip |
cc3200: Make I2C and SPI API the same as in stmhal.
Diffstat (limited to 'docs/library')
-rw-r--r-- | docs/library/pyb.I2C.rst | 162 | ||||
-rw-r--r-- | docs/library/pyb.SPI.rst | 87 |
2 files changed, 66 insertions, 183 deletions
diff --git a/docs/library/pyb.I2C.rst b/docs/library/pyb.I2C.rst index d3cbed0574..7c22a700b9 100644 --- a/docs/library/pyb.I2C.rst +++ b/docs/library/pyb.I2C.rst @@ -45,11 +45,9 @@ To receive inplace, first create a bytearray:: data = bytearray(3) # create a buffer i2c.recv(data) # receive 3 bytes, writing them into data -.. only:: port_pyboard +You can specify a timeout (in ms):: - You can specify a timeout (in ms):: - - i2c.send(b'123', timeout=2000) # timout after 2 seconds + i2c.send(b'123', timeout=2000) # timout after 2 seconds A master must specify the recipient's address:: @@ -57,29 +55,15 @@ A master must specify the recipient's address:: i2c.send('123', 0x42) # send 3 bytes to slave with address 0x42 i2c.send(b'456', addr=0x42) # keyword for address -.. only:: port_pyboard - - Master also has other methods:: - - i2c.is_ready(0x42) # check if slave 0x42 is ready - i2c.scan() # scan for slaves 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) - -.. only:: port_wipy - - There are also other methods:: - - i2c.is_ready(0x42) # check if slave 0x42 is ready - i2c.scan() # scan for slaves 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) # write 'abc' (3 bytes) to memory of slave 0x42 - # starting at address 2 in the slave +Master also has other methods:: + i2c.is_ready(0x42) # check if slave 0x42 is ready + i2c.scan() # scan for slaves 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 Constructors ------------ @@ -102,7 +86,7 @@ Constructors .. only:: port_wipy .. class:: pyb.I2C(bus, ...) - + Construct an I2C object on the given bus. `bus` can only be 1. With no additional parameters, the I2C object is created but not initialised (it has the settings from the last initialisation of @@ -141,118 +125,58 @@ Methods Check if an I2C device responds to the given address. Only valid when in master mode. -.. only:: port_pyboard +.. method:: i2c.mem_read(data, addr, memaddr, timeout=5000, addr_size=8) - .. method:: i2c.mem_read(data, addr, memaddr, timeout=5000, addr_size=8) - - Read from the memory of an I2C device: - - - ``data`` can be an integer (number of bytes to read) or a buffer to read into - - ``addr`` is the I2C device address - - ``memaddr`` is the memory location within the I2C device - - ``timeout`` is the timeout in milliseconds to wait for the read - - ``addr_size`` selects width of memaddr: 8 or 16 bits + Read from the memory of an I2C device: - Returns the read data. - This is only valid in master mode. + - ``data`` can be an integer (number of bytes to read) or a buffer to read into + - ``addr`` is the I2C device address + - ``memaddr`` is the memory location within the I2C device + - ``timeout`` is the timeout in milliseconds to wait for the read + - ``addr_size`` selects width of memaddr: 8 or 16 bits -.. only:: port_wipy + Returns the read data. + This is only valid in master mode. - .. method:: i2c.mem_read(data, addr, memaddr, addr_size=8) - - Read from the memory of an I2C device: - - - ``data`` can be an integer (number of bytes to read) or a buffer to read into - - ``addr`` is the I2C device address - - ``memaddr`` is the memory location within the I2C device - - ``addr_size`` selects width of memaddr: 8 or 16 bits +.. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8) - Returns the read data. - This is only valid in master mode. + Write to the memory of an I2C device: -.. only:: port_pyboard + - ``data`` can be an integer or a buffer to write from + - ``addr`` is the I2C device address + - ``memaddr`` is the memory location within the I2C device + - ``timeout`` is the timeout in milliseconds to wait for the write + - ``addr_size`` selects width of memaddr: 8 or 16 bits - .. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8) - - Write to the memory of an I2C device: - - - ``data`` can be an integer or a buffer to write from - - ``addr`` is the I2C device address - - ``memaddr`` is the memory location within the I2C device - - ``timeout`` is the timeout in milliseconds to wait for the write - - ``addr_size`` selects width of memaddr: 8 or 16 bits + Returns ``None``. + This is only valid in master mode. - Returns ``None``. - This is only valid in master mode. +.. method:: i2c.recv(recv, addr=0x00, timeout=5000) -.. only:: port_wipy + Receive data on the bus: - .. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8) - - Write to the memory of an I2C device: - - - ``data`` can be an integer or a buffer to write from - - ``addr`` is the I2C device address - - ``memaddr`` is the memory location within the I2C device - - ``addr_size`` selects width of memaddr: 8 or 16 bits - - Returns ``None``. - This is only valid in master mode. - -.. only:: port_pyboard + - ``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) + - ``timeout`` is the timeout in milliseconds to wait for the receive - .. method:: i2c.recv(recv, addr=0x00, timeout=5000) - - Receive data on the bus: - - - ``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) - - ``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, - otherwise the same buffer that was passed in to ``recv``. - -.. only:: port_wipy - - .. method:: i2c.recv(recv, addr=0x00) - - Receive data on the bus: - - - ``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) - - Return value: if ``recv`` is an integer then a new buffer of the bytes received, - otherwise the same buffer that was passed in to ``recv``. + Return value: if ``recv`` is an integer then a new buffer of the bytes received, + otherwise the same buffer that was passed in to ``recv``. .. 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:: port_pyboard - - .. method:: i2c.send(send, addr=0x00, timeout=5000) - - 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) - - ``timeout`` is the timeout in milliseconds to wait for the send - - Return value: ``None``. +.. method:: i2c.send(send, addr=0x00, timeout=5000) -.. only:: port_wipy + Send data on the bus: - .. method:: i2c.send(send, addr=0x00) - - 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) + - ``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) + - ``timeout`` is the timeout in milliseconds to wait for the send - Return value: ``None``. + Return value: ``None``. Constants --------- diff --git a/docs/library/pyb.SPI.rst b/docs/library/pyb.SPI.rst index d6f4bb9637..16aa3e20e1 100644 --- a/docs/library/pyb.SPI.rst +++ b/docs/library/pyb.SPI.rst @@ -25,7 +25,7 @@ there are 3 lines: SCK, MOSI, MISO. parameters to init the SPI bus:: from pyb import SPI - spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0) + spi = SPI(1, SPI.MASTER, baudrate=1000000, polarity=0, phase=0, nss=SPI.ACTIVE_LOW) Only required parameter is mode, must be SPI.MASTER. Polarity can be 0 or 1, and is the level the idle clock line sits at. Phase can be 0 or 1 to @@ -105,7 +105,7 @@ Methods .. only:: port_wipy - .. method:: spi.init(mode, baudrate=328125, \*, polarity=1, phase=0, bits=8, nss=SPI.ACTIVE_LOW) + .. method:: spi.init(mode, baudrate=1000000, \*, polarity=0, phase=0, bits=8, nss=SPI.ACTIVE_LOW) Initialise the SPI bus with the given parameters: @@ -122,78 +122,37 @@ Methods Printing the SPI object will show you the computed baudrate and the chosen prescaler. -.. only:: port_pyboard - - .. method:: spi.recv(recv, \*, timeout=5000) - - Receive data on the bus: - - - ``recv`` can be an integer, which is the number of bytes to receive, - or a mutable buffer, which will be filled with received bytes. - - ``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, - otherwise the same buffer that was passed in to ``recv``. +.. method:: spi.recv(recv, \*, timeout=5000) -.. only:: port_wipy + Receive data on the bus: - .. method:: spi.recv(recv) - - Receive data on the bus: - - - ``recv`` can be an integer, which is the number of bytes to receive, - or a mutable buffer, which will be filled with received bytes. - - Return value: if ``recv`` is an integer then a new buffer of the bytes received, - otherwise the same buffer that was passed in to ``recv``. + - ``recv`` can be an integer, which is the number of bytes to receive, + or a mutable buffer, which will be filled with received bytes. + - ``timeout`` is the timeout in milliseconds to wait for the receive. -.. only:: port_pyboard + Return value: if ``recv`` is an integer then a new buffer of the bytes received, + otherwise the same buffer that was passed in to ``recv``. - .. method:: spi.send(send, \*, timeout=5000) - - Send data on the bus: - - - ``send`` is the data to send (an integer to send, or a buffer object). - - ``timeout`` is the timeout in milliseconds to wait for the send. - - Return value: ``None``. +.. method:: spi.send(send, \*, timeout=5000) -.. only:: port_wipy + Send data on the bus: - .. method:: spi.send(send) - - Send data on the bus: - - - ``send`` is the data to send (an integer to send, or a buffer object). - - Return value: ``None``. + - ``send`` is the data to send (an integer to send, or a buffer object). + - ``timeout`` is the timeout in milliseconds to wait for the send. -.. only:: port_pyboard + Return value: ``None``. - .. method:: spi.send_recv(send, recv=None, \*, timeout=5000) - - Send and receive data on the bus at the same time: - - - ``send`` is the data to send (an integer to send, or a buffer object). - - ``recv`` is a mutable buffer which will be filled with received bytes. - It can be the same as ``send``, or omitted. If omitted, a new buffer will - be created. - - ``timeout`` is the timeout in milliseconds to wait for the receive. - - Return value: the buffer with the received bytes. +.. method:: spi.send_recv(send, recv=None, \*, timeout=5000) -.. only:: port_wipy + Send and receive data on the bus at the same time: - .. method:: spi.send_recv(send, recv=None) - - Send and receive data on the bus at the same time: - - - ``send`` is the data to send (an integer to send, or a buffer object). - - ``recv`` is a mutable buffer which will be filled with received bytes. - It can be the same as ``send``, or omitted. If omitted, a new buffer will - be created. + - ``send`` is the data to send (an integer to send, or a buffer object). + - ``recv`` is a mutable buffer which will be filled with received bytes. + It can be the same as ``send``, or omitted. If omitted, a new buffer will + be created. + - ``timeout`` is the timeout in milliseconds to wait for the receive. - Return value: the buffer with the received bytes. + Return value: the buffer with the received bytes. Constants --------- @@ -219,4 +178,4 @@ Constants .. data:: SPI.ACTIVE_LOW .. data:: SPI.ACTIVE_HIGH - decides the polarity of the NSS pin + selects the polarity of the NSS pin |