I am trying to use the Nicla Vision as an I2C peripheral with a MKRWAN 1310 as the I2C controller using the Arduino Wire library. I haven't found any examples for the Nicla Vision, but it seemed that the Wire examples for the MKRWAN 1310 should work as they are very basic.
I am using the master_reader.ino code on the MKRWAN 1310 to request data from the Nicla Vision which is running the slave_sender.ino code. I'll include them below - I have not modified the example code.
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(2); // join i2c bus with address #2
Wire.onRequest(requestEvent); // register event
}
void loop()
{
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
The problem that I am having is that even though the Wire.requestFrom is running continuously on the MKRWAN 1310, I only get a single response from the Nicla Vision. I can get another single response by resetting the Nicla Vision. (By single response I mean that I receive the "hello " string once).
Is there anything else that I should be doing or is this a known issue?
I can run the inverse (Nicla Vision as the controller and MKRWAN 1310 as the peripheral using that example code) and that runs correctly.