Skip to content

Send byte by slave i2c #14

@ovelhoandre

Description

@ovelhoandre

Hi!

I'm trying to implement a model similar to a memory, where the RA-08 is an i2c slave, receiving a register and returning the corresponding value, but the application gets stuck in while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_TRANS_EMPTY) != SET);

Here the code:

/* wait slave address detected */
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_SLAVE_ADDR_DET) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_SLAVE_ADDR_DET);

/* read RW byte */
i2c_set_receive_mode(I2C_SLAVE_NUM, I2C_ACK);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL);
board_data->buff.rw = i2c_receive_data(I2C_SLAVE_NUM);

/* read Data Len byte */
i2c_set_receive_mode(I2C_SLAVE_NUM, I2C_ACK);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL);
board_data->buff.len = i2c_receive_data(I2C_SLAVE_NUM);

/* read Reg byte */
i2c_set_receive_mode(I2C_SLAVE_NUM, I2C_ACK);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL);
board_data->buff.reg = i2c_receive_data(I2C_SLAVE_NUM);

/* wait slave address detected */
i2c_set_receive_mode(I2C_SLAVE_NUM, I2C_ACK);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_RECV_FULL);
i2c_receive_data(I2C_SLAVE_NUM);

i2c_send_data(I2C_SLAVE_NUM, 3);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_TRANS_EMPTY);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_TRANS_EMPTY) != SET);

i2c_send_data(I2C_SLAVE_NUM, 1);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_TRANS_EMPTY);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_TRANS_EMPTY) != SET);

/* wait slave stop detected */
i2c_set_receive_mode(I2C_SLAVE_NUM, I2C_ACK);
while (i2c_get_flag_status(I2C_SLAVE_NUM, I2C_FLAG_SLAVE_STOP_DET) != SET);
i2c_clear_flag_status(I2C_SLAVE_NUM, I2C_FLAG_SLAVE_STOP_DET);

Grateful for any help!

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