Ai-Thinker-LoRaWAN-Ra-08 icon indicating copy to clipboard operation
Ai-Thinker-LoRaWAN-Ra-08 copied to clipboard

Send byte by slave i2c

Open ovelhoandre opened this issue 1 year ago • 0 comments

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!

ovelhoandre avatar Nov 29 '23 11:11 ovelhoandre