Skip to content

Added the repeated-start feature in I2C driver #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 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 != false) {
_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,14 @@ void TwoWire::beginTransmission(int address)
//
uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
UNUSED(sendStop);
//UNUSED(sendStop);
int8_t ret = 4;
// check transfer options and store it in the I2C handle
if (sendStop == false) {
_i2c.handle.XferOptions = I2C_FIRST_FRAME;
} else {
_i2c.handle.XferOptions = I2C_FIRST_AND_LAST_FRAME;
}

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