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

Send byte by slave i2c #14

Open
ovelhoandre opened this issue Nov 29, 2023 · 0 comments
Open

Send byte by slave i2c #14

ovelhoandre opened this issue Nov 29, 2023 · 0 comments

Comments

@ovelhoandre
Copy link

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!

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

No branches or pull requests

1 participant