Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/arduino/stm32/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ i2c_status_e i2c_master_write(i2c_t *obj, uint8_t dev_address,
}

do {
if (HAL_I2C_Master_Transmit_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
if (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle), dev_address, data, size, obj->handle.XferOptions) == HAL_OK) {
ret = I2C_OK;
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
Expand Down Expand Up @@ -778,7 +778,7 @@ i2c_status_e i2c_master_read(i2c_t *obj, uint8_t dev_address, uint8_t *data, uin
uint32_t delta = 0;

do {
if (HAL_I2C_Master_Receive_IT(&(obj->handle), dev_address, data, size) == HAL_OK) {
if (HAL_I2C_Master_Seq_Receive_IT(&(obj->handle), dev_address, data, size, obj->handle.XferOptions) == HAL_OK) {
ret = I2C_OK;
// wait for transfer completion
while ((HAL_I2C_GetState(&(obj->handle)) != HAL_I2C_STATE_READY)
Expand Down
14 changes: 12 additions & 2 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C" {

#include "Wire.h"

#define I2C_NO_OPTION_FRAME 0xFFFF0000U /*!< XferOptions default value */
// Initialize Class Variables //////////////////////////////////////////////////
uint8_t *TwoWire::rxBuffer = nullptr;
uint8_t TwoWire::rxBufferAllocated = 0;
Expand Down Expand Up @@ -116,7 +117,6 @@ void TwoWire::setClock(uint32_t frequency)

uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
{
UNUSED(sendStop);
if (_i2c.isMaster == 1) {
allocateRxBuffer(quantity);
// error if no memory block available to allocate the buffer
Expand Down Expand Up @@ -146,6 +146,11 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres

// perform blocking read into buffer
uint8_t read = 0;
if (sendStop != 0) {
_i2c.handle.XferOptions = I2C_LAST_FRAME;
} else {
_i2c.handle.XferOptions = I2C_NO_OPTION_FRAME;
}
if (I2C_OK == i2c_master_read(&_i2c, address << 1, rxBuffer, quantity)) {
read = quantity;
}
Expand Down Expand Up @@ -211,8 +216,13 @@ void TwoWire::beginTransmission(int address)
//
uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
UNUSED(sendStop);
int8_t ret = 4;
// check transfer options and store it in the I2C handle
if (sendStop == 0) {
_i2c.handle.XferOptions = I2C_FIRST_FRAME;
} else {
_i2c.handle.XferOptions = I2C_FIRST_AND_LAST_FRAME;
}

if (_i2c.isMaster == 1) {
// transmit buffer (blocking)
Expand Down