• sales

    +86-0755-88291180

【MicroPython】machine.UART Function

  • machine.UART(id,baudrate=115200,bits=8,parity=None,stop=1,tx=None,rx=None):
    • UART object constructor, used to initialize the corresponding channel and pin.
    • id: use the UART channel, which can be 0 or 1;
    • baudrate: baud rate parameter
    • bits: data bit length
    • parity: parity bit
    • stop: stop bit length
    • tx: TXD pin, should be a Pin object
    • rx: RXD pin, should be a Pin object

machine.UART is the constructor of the UART object, which is used to initialize the corresponding channel and pin. D The first parameter id is to use the UART channel, which can be 0 or 1.

The second parameter baudrate is the baud rate used.

The third parameter bits is the data bit length (only 8 bits are valid at this stage).

The fourth parameter parity is whether to use the parity bit.

The fifth parameter stop is the length of the stop bit.

The sixth and seventh parameters tx and rx are transceiver pins, which should be Pin objects.

  • UART.any():
    • The any function is used to detect whether there is data in the current receive buffer. If there is data in the receive buffer, it returns 1, otherwise it returns 0.
  • UART.read([nbytes]):
    • The read function is used to read strings.
    • nbytes: If 'nbytes is specified, read at most this many bytes, otherwise read as much data as possible.
  • UART.readline()
    • The readline function reads a line, ending with a newline character.
  • UART.readinto(buf[, nbytes])
    • readinto: store the read string in the specified buffer
    • buf: used to specify the cache
    • nbytes: If 'nbytes is specified, read at most this many bytes, otherwise read as much data as possible.
  • The readinto function stores the read string in the specified cache. buf is used to specify the cache nbytes and the function of the read function nbytes above is the same
  • UART.write(buf)

The write function, used to send a string, returns the number of bytes sent by the value. buf: Sending a string The write function is used to send a string and return the number of bytes sent. The parameter buf is the string to be sent.

  • UART.sendbreak()

The sendbreak function sends a stop signal on the bus. This will drive the bus low for longer than the normal transmission of the character takes.