Skip to content
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

i2c_write_raw_blocking needs nostop parameter #812

Open
sigmafx opened this issue May 5, 2022 · 3 comments
Open

i2c_write_raw_blocking needs nostop parameter #812

sigmafx opened this issue May 5, 2022 · 3 comments
Assignees
Milestone

Comments

@sigmafx
Copy link

sigmafx commented May 5, 2022

Whilst writing to an I2C EEPROM it's necessary to write eeprom memory address followed by the data to write without a STOP between the address and the data. A typical write function would accept a memory address and data as separate parameters. This is best written to the EEPROM in 2 API calls:
1st: Sends device address and eeprom memory address
2nd: Sends data, followed by a STOP

The only achievable way is using the following APIs:

        // nostop is true so STOP isn't sent allowing data bytes to follow immediately
        i2c_write_blocking(m_instance, m_devAddr, &address, 1, true);
        i2c_write_raw_blocking(m_instance, &data, sizeof(data));

However, i2c_write_raw_blocking does not write a STOP.

It would be helpful to include the nostop paramter to i2c_write_raw_blocking function:

static inline void i2c_write_raw_blocking(i2c_inst_t *i2c, const uint8_t *src, size_t len, bool nostop) {
    for (size_t i = 0; i < len; ++i) {
        bool last = i == len - 1;

        // TODO NACK or STOP on end?
        while (!i2c_get_write_available(i2c))
            tight_loop_contents();
        i2c_get_hw(i2c)->data_cmd =
            bool_to_bit(last && !nostop) << I2C_IC_DATA_CMD_STOP_LSB |
            *src++;
    }
}

There's already a comment in there about this.

@kilograham kilograham added this to the 1.6.0 milestone May 26, 2023
@kilograham
Copy link
Contributor

note #1049 which also deals with I2C functions - perhaps we need an additional config

@kaimac1
Copy link

kaimac1 commented Mar 7, 2024

this is also very useful for driving OLED displays, where the frame data needs to be preceded by a single 0x40 byte.

@sigmafx 's function needs the following after the for loop to wait for the STOP bit to actually be generated:

while (!(i2c->hw->raw_intr_stat & I2C_IC_RAW_INTR_STAT_STOP_DET_BITS)) tight_loop_contents(); 

@kilograham kilograham modified the milestones: 1.6.1, 1.6.0 May 20, 2024
@peterharperuk peterharperuk modified the milestones: 1.6.0, 1.7.0 Jul 25, 2024
@lurch
Copy link
Contributor

lurch commented Sep 1, 2024

Does #1495 fix this, or is that a different problem entirely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants