Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SoftI2C by
SoftI2C Class Reference
A software I2C class in case you run out of hardware I2C pins or cannot use those for another reason. More...
#include <SoftI2C.h>
Public Member Functions | |
| SoftI2C (PinName sda, PinName scl) | |
| Create an software I2C Master interface, connected to the specified pins. | |
| void | frequency (int hz) |
| Set the frequency of the I2C interface. | |
| int | read (int address, char *data, int length, bool repeated=false) |
| Read from an I2C slave. | |
| int | read (int ack) |
| Read a single byte from the I2C bus. | |
| int | write (int address, const char *data, int length, bool repeated=false) |
| Write to an I2C slave. | |
| int | write (int data) |
| Write single byte out on the I2C bus. | |
| void | start (void) |
| Create a (re-)start condition on the I2C bus. | |
| void | stop (void) |
| Create a stop condition on the I2C bus. | |
Detailed Description
A software I2C class in case you run out of hardware I2C pins or cannot use those for another reason.
The class is a drop-in replacement of the classic mbed I2C class: include this file in your program, replace I2C with SoftI2C when creating the object and it should work properly without other modifications.
Definition at line 14 of file SoftI2C.h.
Constructor & Destructor Documentation
| SoftI2C | ( | PinName | sda, |
| PinName | scl | ||
| ) |
Create an software I2C Master interface, connected to the specified pins.
- Parameters:
-
sda I2C data pin scl I2C clock pin
Definition at line 3 of file SoftI2C.cpp.
Member Function Documentation
| void frequency | ( | int | hz ) |
Set the frequency of the I2C interface.
Note that the delay of the DigitalInOuts is not compensated: the real frequency will be lower than the one set. However since I2C is a synchronous protocol this shouldn't affect functionality
- Parameters:
-
hz The bus frequency in hertz
Definition at line 15 of file SoftI2C.cpp.
| int read | ( | int | address, |
| char * | data, | ||
| int | length, | ||
| bool | repeated = false |
||
| ) |
Read from an I2C slave.
Performs a complete read transaction. The bottom bit of the address is forced to 1 to indicate a read.
- Parameters:
-
address 8-bit I2C slave address [ addr | 1 ] Pointer to the byte-array data to read to length Number of bytes to read repeated Repeated start, true - do not send stop at end
- Returns:
- 0 on success (ack), non-0 on failure (nack)
Definition at line 19 of file SoftI2C.cpp.
| int read | ( | int | ack ) |
Read a single byte from the I2C bus.
- Parameters:
-
ack indicates if the byte is to be acknowledged (1 = acknowledge)
- Returns:
- the byte read
Definition at line 60 of file SoftI2C.cpp.
| void start | ( | void | ) |
Create a (re-)start condition on the I2C bus.
Definition at line 139 of file SoftI2C.cpp.
| void stop | ( | void | ) |
Create a stop condition on the I2C bus.
Definition at line 157 of file SoftI2C.cpp.
| int write | ( | int | data ) |
Write single byte out on the I2C bus.
- Parameters:
-
data data to write on the bus
- Returns:
- '1' if an ACK is received, '0' otherwise
Definition at line 99 of file SoftI2C.cpp.
| int write | ( | int | address, |
| const char * | data, | ||
| int | length, | ||
| bool | repeated = false |
||
| ) |
Write to an I2C slave.
Performs a complete write transaction. The bottom bit of the address is forced to 0 to indicate a write.
- Parameters:
-
address 8-bit I2C slave address [ addr | 0 ] Pointer to the byte-array data to send length Number of bytes to send repeated Repeated start, true - do not send stop at end
- Returns:
- 0 on success (ack), non-0 on failure (nack)
Definition at line 39 of file SoftI2C.cpp.
Generated on Fri Jul 15 2022 09:54:37 by
1.7.2
