aegotheles 2 Posted April 3, 2015 Share Posted April 3, 2015 Sorry to bother if I'm missing something obvious in the documentation - but there's something I can't seem to figure out. I'm migrating a simple datalogger that uses an ATTiny24a, BMP180, and an external EEPROM to (hopefully!) take advantage of the power savings and FRAM on the MSP430FR5969. I've attached a sample of my code by I can't seem to find anywhere similar functions to EEPROM.read and EEPROM.write. All I've managed to find is FRAM_write<enter # of bits here> in the fram.c in the DriverLib library. /*Simple code to transmit ID and basic sensor data using OOK */ #include <EEPROM.h>int pulse = 50; //transmit pulse lengthint interval = 25; //interpulse lengthint sample = 5000; //time between sensor samplingint gap = 500; //time between transmissionsint idArray[] = {1,0,1,1}; //basic tag ID in binary, e.g. 11 = {1,0,1,1}int addr = 0; //initial EEPROM write addressint address = 0; //initial EEPROM read addressvoid setup() { Serial.begin(115200); // initialize digital pin 13 as an output. pinMode(13, OUTPUT);}void loop() {//DATA_COLLECTION AND EEPROM WRITE/READ________________________________________________________________int sensorData = random(1024); // this is the BMP180 data but now it's just random junk for testing if (addr <= 9){ EEPROM.write(addr, sensorData); addr = addr + 1; delay(sample); } if (addr > 9){ int sensorTransmit = EEPROM.read(address);//ID_ARRAY_TRANSMISSION________________________________________________________________________________ for (int j=0; j<4; j++){ if (idArray[j] == 1){ digitalWrite(13, HIGH); delay(pulse); }else{ digitalWrite(13, LOW); delay(pulse); } digitalWrite(13,LOW); delay(interval); }//SENSOR_ONE_TRANSMISSION________________________________________________________________________________ for (int k=0; k<8; k++){ digitalWrite(13, bitRead(sensorTransmit, k)); delay(pulse); digitalWrite(13, LOW); delay(interval); byte state = bitRead(sensorTransmit,k); Serial.print(state); } Serial.println(); digitalWrite(13, LOW); delay(gap); address = address + 1; if (address > 9){ address = 0; addr = 0; } }} Basically all I'm trying to do is log data to the FRAM at a specified interval, then after a certain number of datalogging events read it back out and convert to on-off keying. Each datalogger has it's own unqiue ID. At a later time I want to look into the different lower power modes on the MSP430, but first things first. Again, I apologize if I'm overlooking something quite simple. Quote Link to post Share on other sites
spirilis 1,265 Posted April 3, 2015 Share Posted April 3, 2015 So I don't recall offhand if Energia provides an "EEPROM" library like Arduino per se, but you will find reading/writing FRAM is actually a little more obvious than you think. The practice is to define an array of bytes but declare it with __attribute__((section(".text"))) so that the compiler & linker stuffs it in the same segment of memory (FRAM) as the rest of the code. Then you don't use read or write calls to hit it- you just literally access the array like you would any array you've declared in RAM. The magic is that its contents retain all changes across resets, unlike a true RAM array. It will get erased if you reflash the sketch or flash a new sketch though. Sent from my Galaxy Note II with Tapatalk 4 aegotheles 1 Quote Link to post Share on other sites
aegotheles 2 Posted April 3, 2015 Author Share Posted April 3, 2015 Thanks so much for the help. Just to avoid possible confusion I'm not intending on using an EEPROM, that was just old code from the Arduino and ATTiny24 setup. So I have a few more questions. 1) Do I need to specify an absolute address in with_attribute_((section(".text"))) for it know where to place the 16 bit integer from each reading from the sensor, 2) does it need have a address specified each time in the loop when it adds sensor data and 3) do I need to preallocate the total number of samples? Quote Link to post Share on other sites
spirilis 1,265 Posted April 3, 2015 Share Posted April 3, 2015 #1 and #2 no, although I recommend using the native datatype of the info e.g. "int16_t" or "uint16_t" for signed or unsigned 16-bit integers respectively. For #3 - yes. That will be the array size, e.g. the number in brackets, like: __attribute__((section(".text"))) uint16_t SampleStore[256]; // FRAM storage space for 256 16-bit samples Sent from my Galaxy Note II with Tapatalk 4 aegotheles 1 Quote Link to post Share on other sites
spirilis 1,265 Posted April 3, 2015 Share Posted April 3, 2015 Actually for #2, it does not need a "physical address" but what it DOES need is an array subscript, e.g.: SampleStore[15] = data; How you store the current # of samples is a good question. Another FRAM variable could be used: __attribute__((section(".text"))) int SampleCount = 0; // Current # of samples stored in SampleStore, initialized as 0 on first flashing Then you would store samples with: SampleStore[sampleCount++] = data; And each run of that statement stores data in a unique location, and "SampleCount" increments likewise, surviving across resets. Sent from my Galaxy Note II with Tapatalk 4 aegotheles 1 Quote Link to post Share on other sites
spirilis 1,265 Posted April 4, 2015 Share Posted April 4, 2015 Also to be clear, those FRAM variables or arrays should be declared in the global context, i.e. outside of any function. Sent from my Galaxy Note II with Tapatalk 4 aegotheles 1 Quote Link to post Share on other sites
spirilis 1,265 Posted April 4, 2015 Share Posted April 4, 2015 Lastly, check out this thread: http://forum.43oh.com/topic/5474-energia-and-wolverine-tips/ Sent from my Galaxy Note II with Tapatalk 4 aegotheles 1 Quote Link to post Share on other sites
aegotheles 2 Posted April 4, 2015 Author Share Posted April 4, 2015 Great! Thanks again for all the info. I'll read this over and hopefully post a working example tomorrow. Quote Link to post Share on other sites
aegotheles 2 Posted April 4, 2015 Author Share Posted April 4, 2015 It worked! Now to tackle the BMP180. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.