通信协议大致如下:
- wait for message header
ad_i2c_start_slave(ack, sizeof ack, msgHeader, sizeof msgHeader, callbacks, OS_EVENT_FOREVER);
…
ad_i2c_start_slave(ack, sizeof ack, msgPayload, sizeof msgPayload, callbacks, TIMEOUT);
ad_i2c_start_slave(ack, sizeof ack, waiting_for_result, sizeof waiting_for_result, callback, TIMEOUT);
- send result
ad_i2c_start_slave(ack, sizeof ack, result, sizeof result, callback, TIMEOUT);根据我的经验,我不能正确处理读请求回调,所以我选择始终为ad_i2c_start_slave()提供wbuf和rbuf,这样我只关心data_sent和data_received回调。所以在每个阶段(上面),i2c主机都需要发送数据和读取数据(比如一个确认)。所以基本上我在等待data_sent和data_received事件被触发,以推进协议的下一阶段(见上文)。
然而有时他们i2c总线挂起(SCLK保持低)。我猜这是因为请求的数据(或发送的数据)不是由软件处理的。 How can this happen? I think this can occur when during the switches of the buffer between each stage. However shouldn't the old buffers be used instead? or are these buffers used only one time?
Another issue that can occur I'm guess is that there's pending transactions that I do not know how to cancel in the case of timesouts. See my other post here : https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bl...
So my question is how can use the ad_i2c_start_slave() with timeouts the way how described in the protocol mentioned above and or do you have any suggestions on how I can implement this.
PS. The issue I was having before with read_request callback is that reading the data from the buffer didn't really stop the interrupt (RX_FULL) from continuously being triggered. Perhaps if you have suggestions how this can be done in combination with the protocol I'll be more than welcomed to hear it.