Hi, I am developing an I2C Bootloader, and I am using Microchip/Atmel Studio. I want to use the i2c slave async driver, so the whole callback implementation is ready to use.
The Hardware I am using is a SAMD21G18A MCU on an Arduino MKR ZERO Board.
My question is:
Is there a flag or some simple way to check if the slave device is receiving messages? I want to know if the Master/Primary is done sending data to the Slave/Secondary.
There is the Function "i2c_s_async_get_status" but after some reading my guess is, that this returns the device status and not the state of the Bus.
I hope that this minimal code segment can help in understanding my problem.
#include <atmel_start.h> #include "driver_examples.h" /*Global Var*/ static struct io_descriptor *io; /*Functions*/ static void i2c_startmsg(const struct i2c_s_async_descriptor *const descr){ uint8_t c; io_read(io, &c, 1); } void i2c_setup(void){ i2c_s_async_get_io_descriptor(&I2C_0, &io); i2c_s_async_register_callback(&I2C_0, I2C_S_RX_COMPLETE, i2c_startmsg); i2c_s_async_enable(&I2C_0); } int main(void) { /* Initializes MCU, drivers and middleware */ atmel_start_init(); i2c_setup(); while (1) { gpio_toggle_pin_level(LED_BUILTIN); delay_ms(1000); if( HERE SOME CONDITION TO CHECK BUS STATUS ){ } } }
I am a new player in programming the big boy MCUs, so please be kind and imply that there can be fundamental flaws in my approach.
Thank you in advance.