I2C controller or peripheral on one RP2040 I2C peripheral; sketches use Wire. More...
#include <Wire.h>
Public Member Functions | |
| PhyduinoWire (i2c_inst_t *i2c, pin_size_t sda, pin_size_t scl) | |
| Binds Wire to an I2C peripheral and its pins; nothing is set up until begin(). | |
| void | begin () override |
| Starts as a controller, at 100 kHz unless setClock() was called. | |
| void | begin (uint8_t address) override |
| Starts as a peripheral that answers at address. | |
| void | end () override |
| Stops I2C and frees the pins. | |
| void | setClock (uint32_t hz) override |
| Sets the bus clock; applies at once if already started. | |
Controller | |
| void | beginTransmission (uint8_t address) override |
| Starts a write to a device; queue the bytes with write(). | |
| uint8_t | endTransmission (bool sendStop) override |
| Sends the queued bytes. | |
| uint8_t | endTransmission () override |
| Sends the queued bytes and ends with a stop. | |
| size_t | requestFrom (uint8_t address, size_t length, bool sendStop) override |
| Reads bytes from a device into the receive buffer; take them with read(). | |
| size_t | requestFrom (uint8_t address, size_t length) override |
| Reads bytes from a device and ends with a stop. | |
Data (controller and peripheral) | |
| size_t | write (uint8_t data) override |
| Queues one byte: for endTransmission(), or as the reply in onRequest(). | |
| size_t | write (const uint8_t *data, size_t length) override |
| Queues several bytes: for endTransmission(), or as the reply in onRequest(). | |
| int | available () override |
| Number of received bytes waiting to be read. | |
| int | read () override |
| Takes the next received byte. | |
| int | peek () override |
| Next received byte, left in the buffer. | |
| void | flush () override |
| Does nothing; kept for Arduino compatibility. | |
Peripheral | |
The callbacks run inside the I2C interrupt: keep them short. | |
| void | onReceive (void(*callback)(int)) override |
| Sets the function called after a controller has written to this board. | |
| void | onRequest (void(*callback)()) override |
| Sets the function called when a controller reads from this board. | |
Static Public Attributes | |
| static constexpr size_t | kBufferSize = 256 |
| Largest number of bytes in one transmission or request. | |
I2C controller or peripheral on one RP2040 I2C peripheral; sketches use Wire.
Every transfer gives up after 50 ms if the bus is stuck.
|
inline |
Binds Wire to an I2C peripheral and its pins; nothing is set up until begin().
| i2c | pico-sdk I2C (i2c0 or i2c1). |
| sda | Arduino pin for SDA. |
| scl | Arduino pin for SCL. |
|
override |
Number of received bytes waiting to be read.
|
override |
Starts as a peripheral that answers at address.
Set onReceive() and onRequest() first.
| address | 7-bit address, 0x08-0x77. |
|
override |
Starts a write to a device; queue the bytes with write().
| address | 7-bit device address. |
|
inlineoverride |
Sends the queued bytes and ends with a stop.
|
override |
Sends the queued bytes.
With no bytes queued it only checks that the device answers, which is what I2C scanners use.
| sendStop | true to end with a stop; false to keep the bus for a following requestFrom() (repeated start). |
|
inlineoverride |
Sets the function called after a controller has written to this board.
| callback | Function taking the number of bytes received; read them with read(). |
|
inlineoverride |
Sets the function called when a controller reads from this board.
| callback | Function that queues the reply with write(). |
|
override |
Next received byte, left in the buffer.
|
override |
Takes the next received byte.
|
inlineoverride |
Reads bytes from a device and ends with a stop.
| address | 7-bit device address. |
| length | Number of bytes, at most kBufferSize. |
|
override |
Reads bytes from a device into the receive buffer; take them with read().
| address | 7-bit device address. |
| length | Number of bytes, at most kBufferSize. |
| sendStop | true to end with a stop; false to keep the bus. |
|
override |
Sets the bus clock; applies at once if already started.
| hz | Clock in Hz, usually 100000 or 400000. |
|
override |
Queues several bytes: for endTransmission(), or as the reply in onRequest().
| data | Bytes to queue. |
| length | Number of bytes. |
|
override |
Queues one byte: for endTransmission(), or as the reply in onRequest().
| data | Byte to queue. |