I have an application where I want to read a few values from the Spark module. But I would prefer to read them all at ones, and then have them returned simultaneously. The obvious way to do this appears to be through the Spark.variable function, since there is no way to return anything but an Integer through the Spark.function function.
The thing is, I want to reset the values that I am reading when I do the read. I suppose I could expose functions and variables to do the following, but it is not what I would call ‘elegant’:
Gather: Take the values, place them into a string, and reset the original values
Download: Send the string to the user through the Spark.variable function
A preferred solution, at least from my point of view since I am guessing that string returns from functions are not likely to be supported any time soon, would be a callback that could let my program know when a variable has been read. I could be keeping the string buffer up to date, and then clear the underlying counters when the variable is read.
Thanks for any assistance
Darryl VK2TDS
P.S. I now have a FM24C256 FRAM working with the Spark. I will make a post in the next few days on my experiences interfacing it
Hi… Hijacking my own thread to talk about FRAM… The FM24C256 device.
I am just working out some bugs… But I have it working for short saves and loads. Longer needs a bit more work…
Save is first…
Wire.beginTransmission(0x50);
Wire.write(0x00); // send the address to write
Wire.write(0x00); // send the address to write
Wire.write(startTime & 0xFF); // send the address to write
Wire.write((startTime >> 8) & 0xFF); // send the address to write
Wire.write((startTime >> 16) & 0xFF); // send the address to write
Wire.write((startTime >> 24) & 0xFF); // send the address to write
Wire.endTransmission(); // capture any error codes
And here is load…
Wire.beginTransmission(0x50);
Wire.write(0x00); // send the address to write
Wire.write(0x00); // send the address to write
Wire.endTransmission(); // capture any error codes
Wire.requestFrom (0x50, 4);
gotTime = Wire.read();
gotTime |= (Wire.read() << 8);
gotTime |= (Wire.read() << 16);
gotTime |= (Wire.read() << 24);
In my case, i did not realise that there was a Vbat signal on the CPU that I could attach to a battery, and was thinking of saving the current synchronised time to FRAM once a second in case of reset. But then I found the RTC was fairly good. I plan to use the FRAM for other purposes.
I have attacked my Relay shield with a box cutter to attach the I2C to D0/D1, and am using it with the three address lines open circuit. The signal lines are held high with 4k7 resistors to Vin, since this is a 5V part. I have found the Saleae16 clone that I grabbed from AliExpress to be brilliant for debugging. Whilst the code above works, I am having some issues with longer writes and reads, and I am working on the debugging process, trying to work out if it is my code or the hardware.
Unfortunately it is now late, and that will need to wait until the next day or so. Unfortunately I am away from the office (home) much of tomorrow so I will work on it as soon as I can.
Darryl
p.s. I just realised that the I2C is running at 100 kHz. The CPU and the FRAM are capable of 400 kHz operations, but there is nothing in the documentation for the firmware about changing the frequency…