Skip to content

I2C 'Wait until byte is transferred' loop #85

Closed
@ijager

Description

@ijager

I was reading the i2c code since I want to implement it for another chip. Then I encountered the following loop in the send_byte function:

        // Wait until byte is transferred
        loop {
            let isr = self.i2c.isr.read();
            if isr.berr().bit_is_set() {
                self.i2c.icr.write(|w| w.berrcf().set_bit());
                return Err(Error::BusError);
            } else if isr.arlo().bit_is_set() {
                self.i2c.icr.write(|w| w.arlocf().set_bit());
                return Err(Error::ArbitrationLost);
            } else if isr.nackf().bit_is_set() {
                self.i2c.icr.write(|w| w.nackcf().set_bit());
                return Err(Error::Nack);
            }
            return Ok(());
        }

// Wait until byte is transferred

This loop seems wrong as it only ever runs once. Guess it might still work in practice most of the time. I guess the idea was to wait for txe bit to clear like in two lines above?

while self.i2c.isr.read().txe().bit_is_clear() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions