|
STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
|
← STM32duino documentation
|
TWI/I2C (Wire) controller, usable as master or slave. More...
#include <Wire.h>
Public Member Functions | |
| TwoWire (pin_size_t sda=SDA, pin_size_t scl=SCL) | |
| Construct a TwoWire instance using the given pins. | |
| ~TwoWire () | |
| Destroy the instance, stopping the TWI interface and releasing its buffers (calls end()). | |
| void | setSCL (pin_size_t scl) |
| Set the SCL pin. | |
| void | setSDA (pin_size_t sda) |
| Set the SDA pin. | |
| void | setSCL (PinName scl) |
| Set the SCL pin. | |
| void | setSDA (PinName sda) |
| Set the SDA pin. | |
| void | begin (bool generalCall) |
| Initialize the TWI interface as master. | |
| void | begin (pin_size_t sda, pin_size_t scl) |
| Initialize the TWI interface as master using the given pins. | |
| void | begin (uint8_t address, bool generalCall=false, bool NoStretchMode=false) |
| Initialize the TWI interface as master or slave. | |
| void | begin (int address, bool generalCall=false, bool NoStretchMode=false) |
| Initialize the TWI interface as master or slave. | |
| void | begin () override |
| Initialize the TWI interface as master with the default pins. | |
| void | begin (uint8_t address) override |
| Initialize the TWI interface as master or slave with the default pins. | |
| void | end () override |
| Stop the TWI interface and free the Rx and Tx buffers. | |
| void | setClock (uint32_t freq) override |
| Set the TWI clock frequency. | |
| void | beginTransmission (uint8_t address) override |
| Begin a transmission to a slave device. | |
| void | beginTransmission (int address) |
| Begin a transmission to a slave device. | |
| uint8_t | endTransmission (void) override |
| Send the buffered data to the slave device, ending with a STOP. | |
| uint8_t | endTransmission (bool stopBit) override |
| Send the buffered data to the slave device and end the transmission. | |
| size_t | requestFrom (uint8_t address, size_t len, bool stopBit) override |
| Request bytes from a slave device. | |
| size_t | requestFrom (uint8_t address, size_t len) override |
| Request bytes from a slave device, sending a STOP after the request. | |
| size_t | requestFrom (uint8_t address, size_t len, uint32_t iaddress, uint8_t isize, bool stopBit) |
| Request bytes from a slave device after writing an internal register address. | |
| size_t | write (uint8_t data) override |
| Write a byte. | |
| size_t | write (const uint8_t *data, size_t quantity) override |
| Write bytes. | |
| int | available (void) override |
| Get the number of bytes available for reading from the Rx buffer. | |
| int | read (void) override |
| Read a byte from the Rx buffer. | |
| int | peek (void) override |
| Read the next byte from the Rx buffer without consuming it. | |
| void | flush (void) override |
| Discard the content of the Rx and Tx buffers. | |
| void | onReceive (cb_function_receive_t function) |
| Register the function called when a slave receives data from a master. | |
| void | onReceive (void(*function)(int)) override |
| Register the function called when a slave receives data from a master. | |
| void | onRequest (cb_function_request_t function) |
| Register the function called when a master requests data from this slave. | |
| void | onRequest (void(*function)(void)) override |
| Register the function called when a master requests data from this slave. | |
| size_t | write (unsigned long n) |
| Write a value as a single byte. | |
| size_t | write (long n) |
| Write a value as a single byte. | |
| size_t | write (unsigned int n) |
| Write a value as a single byte. | |
| size_t | write (int n) |
| Write a value as a single byte. | |
| I2C_HandleTypeDef * | getHandle (void) |
| Get the I2C handle, to mix the Arduino API and the STM32Cube HAL API (e.g. | |
TWI/I2C (Wire) controller, usable as master or slave.
| TwoWire::TwoWire | ( | pin_size_t | sda = SDA, |
| pin_size_t | scl = SCL |
||
| ) |
Construct a TwoWire instance using the given pins.
| sda | Pin used for SDA. Default: SDA. |
| scl | Pin used for SCL. Default: SCL. |
|
override |
Get the number of bytes available for reading from the Rx buffer.
Must be called in the slave rx event callback or after requestFrom().
| void TwoWire::begin | ( | bool | generalCall | ) |
Initialize the TWI interface as master.
| generalCall | true to enable the general call address. Default: false. |
| void TwoWire::begin | ( | int | address, |
| bool | generalCall = false, |
||
| bool | NoStretchMode = false |
||
| ) |
Initialize the TWI interface as master or slave.
The reserved address 0x01 initializes the interface as master, any other address initializes it as slave using this address.
| address | 7-bit own address for slave mode, 0x01 for master mode. |
| generalCall | true to enable the general call address. Default: false. |
| NoStretchMode | true to disable clock stretching. Default: false. |
| void TwoWire::begin | ( | pin_size_t | sda, |
| pin_size_t | scl | ||
| ) |
Initialize the TWI interface as master using the given pins.
| sda | Pin used for SDA. |
| scl | Pin used for SCL. |
|
inlineoverride |
Initialize the TWI interface as master or slave with the default pins.
| address | 7-bit own address for slave mode, 0x01 for master mode. |
| void TwoWire::begin | ( | uint8_t | address, |
| bool | generalCall = false, |
||
| bool | NoStretchMode = false |
||
| ) |
Initialize the TWI interface as master or slave.
The reserved address 0x01 initializes the interface as master, any other address initializes it as slave using this address.
| address | 7-bit own address for slave mode, 0x01 for master mode. |
| generalCall | true to enable the general call address. Default: false. |
| NoStretchMode | true to disable clock stretching. Default: false. |
| void TwoWire::beginTransmission | ( | int | address | ) |
Begin a transmission to a slave device.
Data is stored with write() and sent by endTransmission().
| address | 7-bit address of the slave device. |
|
override |
Begin a transmission to a slave device.
Data is stored with write() and sent by endTransmission().
| address | 7-bit address of the slave device. |
|
override |
Send the buffered data to the slave device and end the transmission.
Originally endTransmission() had no parameter. The stopBit parameter indicates whether or not a STOP is performed on the bus: calling endTransmission(false) allows a sketch to perform a repeated start.
| stopBit | true to send a STOP at the end of the transmission, false to keep the bus for a repeated start. |
|
override |
Send the buffered data to the slave device, ending with a STOP.
Equivalent to endTransmission(true). Provided for backward compatibility with the original definition and behaviour of endTransmission().
|
inline |
Get the I2C handle, to mix the Arduino API and the STM32Cube HAL API (e.g.
DMA). Use at your own risk.
| void TwoWire::onReceive | ( | cb_function_receive_t | function | ) |
Register the function called when a slave receives data from a master.
| function | Function called with the number of bytes received. |
|
override |
Register the function called when a slave receives data from a master.
The callback is called with the number of bytes received. Read the data with available() and read() from this callback.
| function | Function called with the number of bytes received. |
| void TwoWire::onRequest | ( | cb_function_request_t | function | ) |
Register the function called when a master requests data from this slave.
| function | Function called on request. |
|
override |
Register the function called when a master requests data from this slave.
Reply to the master with write() from this callback.
| function | Function called on request. |
|
override |
Read the next byte from the Rx buffer without consuming it.
Must be called in the slave rx event callback or after requestFrom().
|
override |
Read a byte from the Rx buffer.
Must be called in the slave rx event callback or after requestFrom().
|
override |
Request bytes from a slave device, sending a STOP after the request.
| address | 7-bit address of the slave device. |
| len | Number of bytes to request. |
|
override |
Request bytes from a slave device.
| address | 7-bit address of the slave device. |
| len | Number of bytes to request. |
| stopBit | true to send a STOP after the request, false to keep the bus for a repeated start. |
| size_t TwoWire::requestFrom | ( | uint8_t | address, |
| size_t | len, | ||
| uint32_t | iaddress, | ||
| uint8_t | isize, | ||
| bool | stopBit | ||
| ) |
Request bytes from a slave device after writing an internal register address.
This allows a repeated start to access the internal registers of a device.
| address | 7-bit address of the slave device. |
| len | Number of bytes to request. |
| iaddress | Internal register address to write before the request. |
| isize | Size in bytes of the internal address (most significant byte first), limited to 3. |
| stopBit | true to send a STOP after the request, false to keep the bus for a repeated start. |
|
override |
Set the TWI clock frequency.
| freq | Clock frequency in Hz. |
|
inline |
|
inline |
|
inline |
|
inline |
|
override |
Write bytes.
Must be called in the slave tx event callback or after beginTransmission() and before endTransmission().
| data | Pointer to the buffer data. |
| quantity | Number of bytes to write. |
|
inline |
Write a value as a single byte.
| n | Value to write, truncated to a byte. |
|
inline |
Write a value as a single byte.
| n | Value to write, truncated to a byte. |
|
override |
Write a byte.
In master transmitter mode the byte is stored in the Tx buffer, in slave mode it is sent to the master. Must be called in the slave tx event callback or after beginTransmission() and before endTransmission().
| data | Byte to write. |
|
inline |
Write a value as a single byte.
| n | Value to write, truncated to a byte. |
|
inline |
Write a value as a single byte.
| n | Value to write, truncated to a byte. |