Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Reset arduino with code on: January 09, 2011, 11:59:33 am
I can still check the box next to beginner  smiley-grin

I will now research 'register' and learn some more. Thanks Udo!
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Reset arduino with code on: January 09, 2011, 10:29:21 am
Gotta love SEARCH! I needed a way to restart my sketch if a condition was met.

 calle_o 's solution worked GREAT for my application. I inserted this code at the end of my sketch:

Code:
void (softReset){
asm volatile ("  jmp 0");
}

Then, at the point in my sketch I wanted to have the reset happen, I added the code:
Code:
softReset();

Hope this helps others seeking the same result.

Quote
Others that have done it that way have reported that it's not a true reset in that the hardware peripherals are not put into their default condition.
 
I am enough of a noob that I dont fully understand what that means! :-? I *think* all my hardware peripherals (pushbuttons, serial 4-digit display,MAX6675 thermocouple board and 24LC256) wont need a reset. The 'softReset' is called after I overwrite the 24LC256 memory with zeros to prepare it for the next test.

But it seems to work in my application so far... I will post back if any problems occur.

[glow]Thanks!!!!!!!![/glow]


3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Wire Library, Wire.begin  Documentation on: July 19, 2010, 06:06:15 am
Thanks Mike!

That looked to be the case, but I couldn't seem to locate any existing code using more than 1 device.

The () after Wire.begin led me to think that there was more to it.

Hope to be writing bytes to the chip this evening. smiley

4  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Wire Library, Wire.begin  Documentation on: July 17, 2010, 11:33:32 am
I am unclear as to whether each device on the bus requires a 'Wire.begin()', with the addresses filled in for the slave/remote devices.

I am currently using the DS1307 RTC (on the Adafruit Data Logger Shield) as the only device on the bus. I wish to add a 24LS256 Memory chip.

Thanks!  

5  Forum 2005-2010 (read only) / Development / Re: TWIPROM - I2C Library for 24LC256 on: July 12, 2010, 06:38:10 pm
Blow some dust off the thread... :o

I am hoping to use my 24LC256 on an arduino/XBee datalogger, but dont find much on this chip.

Any help appreciated. smiley
6  Forum 2005-2010 (read only) / Troubleshooting / Re: Can't Upgrade XBee Firmware on: May 24, 2010, 12:36:57 pm
@Eelke-

THANKS for posting that firmware reset procedure. I had mucked one up, and *almost* thought it was bricked. This brought it back to working, updated status.

 ;D
7  Forum 2005-2010 (read only) / Interfacing / Re: 7 Segment Display with NewSoftSerial on: August 17, 2010, 09:27:56 am
Thank you! I must have been using an alternate/outdated version.

(FedEx has my displays on the truck today smiley )
8  Forum 2005-2010 (read only) / Interfacing / Re: 7 Segment Display with NewSoftSerial on: August 16, 2010, 08:19:45 pm
[glow]@Wesley-[/glow][/b]
I found out the hard way that software generated serial ports are restricted to 9600. Not sure if that applies to all, but a point to ponder. smiley


@tkbyd-
WOW! Nice link. I will have to study that much more. My blue displays come in tomorrow. smiley
9  Forum 2005-2010 (read only) / Interfacing / Re: Sending Temperature using Xbee on: May 31, 2010, 10:51:50 am
Tug on this old thread smiley


Quote
7E 00 0A 83 00 01 1F 00 01 04 00 03 FF 55

7E       -Correct packet header byte

00 0A  -Payload [glow]= Decimal 10 bytes. (Bytes 4-13 this example)[/glow]

83       -Packet type=input line states, 16 bit source address

00 01   - 16 bit source address (MY setting) of transmitting XBee

1F        - RSSI value, or rec'd signal strength [glow](-31dBv, pretty good!)[/glow]

00        -Broadcast options

01        -Sample count glow](03FF is out of range)[/glow]

55         -Checksum

I am also trying to adapt this code to my use. Thanks ScottG for rewriting it without the LED.

Part of the problem at this time is that the byte count in the packet has to be set in the code for my particular setup. At least thats the 'Theory of the Minute'  :-/






10  Forum 2005-2010 (read only) / Interfacing / Re: 24LC256 overwrite and read all sketches on: July 26, 2010, 12:19:22 pm
Hm...no shipping?!? I may have to look into that. I just googled it.

Well, the 'page wrap' during writes had been the major problem in reliable data logging for me using the 24LC256.

Using the two sketches above, and writing values such as F1,F2,F3 and observing the patterns shown by reading it, have proved valueable in writing information properly to the chip.

This may free me from using a SD card that is WAY too big for my purpose. SWEET!

Now... to transmit it via XBee to a roving monitor... smiley  
11  Forum 2005-2010 (read only) / Interfacing / Re: 24LC256 overwrite and read all sketches on: July 26, 2010, 07:44:30 am
I found the 24LC512 for $1.40 each from Newark, same footprint and pinout, but twice the memory for your shield.

http://www.newark.com/jsp/search/productdetail.jsp?SKU=62K0581&CMP=AFC-GB100000001  

I am sure there are others, I just happened to start here.

12  Forum 2005-2010 (read only) / Interfacing / 24LC256 overwrite and read all sketches on: July 25, 2010, 05:00:24 pm
Couple of sketches I made as I learned about the 24LC256.

This one overwrites all the data with FF, or whatever value you choose to substitite. it does it in (2) 30 packet strings, and one (4) packet string. This puts the Internal Address Pointer at the beginning of a Page each time the cycle is complete.


**EDIT** I discovered at the end of the process, after the "OVERWRITE COMPLETE" message, the 'startAddress' value was 1 not 0. I could find no reason for this in the code.  I put a workaround in , I set the value of 'startAddress' to (-1) and things work fine.  I am open to reasons why, however smiley **

New Sketch:
Code:
// Some code to overwrite FF (or other chosen value) in all memory locations in a 24LC256.
// mashup from Volkemon 7/2010



#include <Wire.h>  


char chipAdress=0x50;   // 24LC256 address on the bus, pins a0,a1 and a2 tied to ground. Will not compile as a byte value, only char??


int startAddress = 0;      //overall counter for address location. 16 bit value, will be split into MSB and LSB  
byte startaddrMSB = 0x00; // Most Signifigant Byte, 1/2 of the address in chip memory.         Max val 0x7F
byte startaddrLSB = 0x00; // Least Signifigant Byte, other 1/2 of the address in chip memory.  Max val 0xFF
                      



void setup()

{
  Wire.begin();             // enable the i2c bus
  Serial.begin(19200);      // Make sure you set the serial monitor to match! :)


}



void loop()
{

  
    Serial.print("Writing starting at bite/slot "); Serial.print(startAddress, DEC);  // info sent to serial monitor for debugging.
  Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
                  
  startaddrMSB = highByte(startAddress);
  startaddrLSB = lowByte(startAddress);  
  Wire.send(startaddrMSB);      //First  7 bits of the address
  Wire.send(startaddrLSB);     //Second 8 bits of the address
  
  for (byte ct=0x0; ct<30; ct++)  // loop where we write info to Wire library buffer.30 byte max. first two are used for address.
  {
    
   Wire.send(0xF1);
   startAddress ++;
   if (startAddress >= 0x7FFF){
     Serial.print("OVERWRITE COMPLETE");
     startAddress = (-1);    // if set to zero, address is off by 1 after 1st overwrite. WHY???
     delay(5000);
   }
                    
  }
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
  Serial.print(" Done1.");Serial.print(startAddress);
  
  
  
  
  
  
   Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
  startaddrMSB = highByte(startAddress);
  startaddrLSB = lowByte(startAddress);  
  Wire.send(startaddrMSB);      //First  7 bits of the address
  Wire.send(startaddrLSB);     //Second 8 bits of the address
  
  for (char ct=0x0; ct<30; ct++)  // loop where we write info to Wire library buffer.30 byte max.first two used by address.
  {
    
   Wire.send(0xF2);   // Sends the value 0xFF to Wire library buffer.
   startAddress++;
   if (startAddress >= 0x7FFF){
     Serial.print("OVERWRITE COMPLETE");
     startAddress = (-1);   // if set to zero, address is off by 1 after 1st overwrite. WHY???
     delay(5000);
   }
  }
  
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
  Serial.print(" Done2.");Serial.print(startAddress);
 
 // The first two wire.send loops sent 60 packets, leaving 4 open in the page. This cleans them up, and gets the Internal Address Pointer to an page beginning.

 
    Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
  startaddrMSB = highByte(startAddress);
  startaddrLSB = lowByte(startAddress);  
  Wire.send(startaddrMSB);      //First  7 bits of the address
  Wire.send(startaddrLSB);     //Second 8 bits of the address
  
  for (char ct=0x0; ct<4; ct++)  // loop where we write info to Wire library buffer.4 to clean up the page.
  {
    
   Wire.send(0xF3);   // Sends the value 0xFF to Wire library buffer.
   startAddress++;
   if (startAddress >= 0x7FFF){
     Serial.print("OVERWRITE COMPLETE");
     startAddress = (-1);     // if set to zero, address is off by 1 after 1st overwrite. WHY???
     delay(5000);
   }
  }
  
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
   Serial.print(" Done3."); Serial.println(startAddress);
  
}

This one reads all the data off the card. The data can be read only in 32 byte strings due to limitations in the wire library. starts at the beginning, and goes to the end, actually beyond.. smiley

**EDIT** I had forgotten to put code in the setup loop to put the Internal Address Pointer back to '0'.... :smiley

Code:

// sketch to read entire chip 32 bytes at a time, display on serial monitor with progress indicated.
// July2010- Volkemon tweaked and commented.
//      _ _
//  A0-|oU |-Vcc
//  A1-|   |-WP
//  A2-|   |-SCL
// Vss-|   |-SDA
//      ---
//
//   SDA goes to Arduino 4
//   SCL goes to Arduino 5
//   WP  goes to ground for now. Can be put to Vcc if write protection is needed.
//   Vcc goes to arduino Vcc
//   Vss goes to arduino ground
//   A2, A1, A0 go to ground for now.
//
// They can be also put to either ground or Vcc to control up to 8 memory chips (2^3), giving you 2MBit of memory (8*2^15).
// A2 A1 A0 Binary Address Hex Address
// 0  0  0    0b1010000       0×50
// 0  0  1    0b1010001       0×51
// 0  1  0    0b1010010       0×52
// 0  1  1    0b1010011       0×53
// 1  0  0    0b1010100       0×54
// 1  0  1    0b1010101       0×55
// 1  1  0    0b1010110       0×56
// 1  1  1    0b1010111       0×57
  
#include <Wire.h>

char chipAdress=0x50;        // Binary 10100000 . Three bits after 1010 (currently 000) are used to specify to what A2, A1, A0 are connected to, ground or vcc. See comment above.
                      // Last bit specifies the opertation - 0 for write, 1 for read. This is controlled for you by the Wire library. :)
int block = 0;



void setup()

{
  Wire.begin();           // enable the i2c bus
  Serial.begin(19200);   // Did you set your serial monitor to 19200?
  Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the beginning of memory
 
  Wire.send(0x00);      
  Wire.send(0x00);    
  
  Wire.endTransmission(); // sends Wire buffer to chip, sets Internal Address Pointer to '0'
  
  
}

void loop()
{
  Serial.println("");
  Serial.print(block);
  Wire.requestFrom(chipAdress, 32);          // requests 32 Bytes of data in a packet, maximum string size.
  while(Wire.available()){                // 'while loop' start, Checks to see if data is waiting
    Serial.print("  ");                  // space to format packets on serial monitor
    Serial.print(Wire.receive(), HEX);  // print the values received on the serial monitor
  }                                    // end bracket for 'while loop'
  Wire.endTransmission();           // when 'while loop' is finished (no more data available) 'closes' chip
  //Serial.println("");
  block += 1;
  if (block > 1024){
    Serial.println("End Of Memory");
    delay(5000);
  }
  delay(100);
}
Hope it helps someone... I learned a lot about these little chips today!!
13  Forum 2005-2010 (read only) / Interfacing / Re: EEPROM Help Needed  (BCD to Hex) on: August 16, 2010, 07:53:22 am
For an EBay posting, that is pretty complete.

I note now that the IC's are in removable sockets, and that A2 (pin3) is tied to Vcc in all cases. This would make this a good breakout board for the 24LC08B. It only uses A0 and A1 and can have 4 together on a single bus.
The '08 is the chip that got me into this series, and has a page write size of 16 Bytes! Total memory of 1KB. NOT a good alternative to what you have.  smiley-wink

 
However...
I have no experience with them,(yet) but it looks like the 24LC1025 is a drop in replacement for the 24LC32a's on your board, and the -1025's also need to have A2 tied to Vcc. Write the correct code and you could have a 500 KByte ( 4Mbit ) memory board!



http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=24LC1025-I/P-ND
14  Forum 2005-2010 (read only) / Interfacing / Re: EEPROM Help Needed  (BCD to Hex) on: August 16, 2010, 05:43:23 am
@Danm- Thats a pretty cool board. We should be able to get it going for you.

(In the future, when you post code, click the "#" button above in the toolbar, and cut-n-paste.)

Code:
// They can be also put to either ground or Vcc to control up to 8 memory chips (2^3), giving you 2MBit of memory (8*2^15).
// A2 A1 A0 Binary Address Hex Address
// 0  0  0    0b1010000       0×50
// 0  0  1    0b1010001       0×51
// 0  1  0    0b1010010       0×52
// 0  1  1    0b1010011       0×53
// 1  0  0    0b1010100       0×54
// 1  0  1    0b1010101       0×55
// 1  1  0    0b1010110       0×56
// 1  1  1    0b1010111       0×57
  

The screening on the board is a little misleading, but correct. The 'x' is a bit filled in by the Arduino Wire library based on the 'read or write' status. Note the code (ok, comments from code) above.  0b means the numbers are in binary. Note they all have a MSB (Most Signifigant Byte) of 1010. This is the family code.

The last three bits (ok, four with the bit the Arduino fills in for us) is the address.(LSB, or Least Signifigant Byte) This is determined by which pins (a0,a1 and a2) are connected to ground. Your board has four of eight addresses used, 100,101,110 and 111.

You were right on using the address 0x54. That is 0b1010100, ( or DEC 84, or 0x54), the chip on the upper left.


[glow][size=14]Wait. I see from the EBay pics you have (4) 24LC32 chips on the board.[/size] [/glow]

THAT may explain a lot. :o  (OK, it is early here. I just got up)

Now, all (4) of those chips give you 128K bits (NOT Bytes) together. This is 1/2 of the memory of a 24LC256 chip that my other code was written for. Not a bunch of storage, but lets "use what ya got".

Other differences:

Page write size of 32 Bytes, not 64 like the 24LC256.
Memory addresses are 0x000 to 0xFFF (24LC256 is 0x0000 to 0x7FFF)
128 (32Byte) 'blocks' of memory, 1024 (32Byte) 'blocks' in the 24LC256

Hmmm........

Try this to write F1 thirty times, and F2 twice per page until chip memory is full:

Code:
// Some code to overwrite F1 and F2 (or other chosen values) in all memory locations in a 24LC32a
// mashup from Volkemon 8/2010 for Danm



#include <Wire.h>  


char chipAdress=0x54;   // 24LC32a address on the bus

int startAddress = 0;      //overall counter for address location. 16 bit value, will be split into MSB and LSB  
byte startaddrMSB = 0x00; // Most Signifigant Byte, 1/2 of the address in chip memory.         Max val 0x0F
byte startaddrLSB = 0x00; // Least Signifigant Byte, other 1/2 of the address in chip memory.  Max val 0xFF
                      



void setup()

{
  Wire.begin();             // enable the i2c bus
  Serial.begin(9600);      // Make sure you set the serial monitor to match! :)


}



void loop()
{

  
    Serial.print("Writing starting at bit/slot "); Serial.print(startAddress, DEC);  // info sent to serial monitor for debugging.
  Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
                  
  startaddrMSB = highByte(startAddress);
  startaddrLSB = lowByte(startAddress);  
  Wire.send(startaddrMSB);      //First  7 bits of the address
  Wire.send(startaddrLSB);     //Second 8 bits of the address
  
  for (byte ct=0x0; ct<30; ct++)  // loop where we write info to Wire library buffer.30 byte max. first two are used for address.
  {
    
   Wire.send(0xF1);  // sends F1 to wire buffer
   startAddress ++;
   if (startAddress >= 0x0FFF){
     Serial.print("OVERWRITE COMPLETE");
     startAddress = (-1);    // if set to zero, address is off by 1 after 1st overwrite. WHY???
     delay(5000);
   }
                    
  }
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
  Serial.print(" Done1.");Serial.print(startAddress);
  
  


 // The first loop sent 30 packets, leaving 2 open in the page. This cleans them up, and gets the Internal Address Pointer to an page beginning.


    Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
  startaddrMSB = highByte(startAddress);
  startaddrLSB = lowByte(startAddress);  
  Wire.send(startaddrMSB);      //First  7 bits of the address
  Wire.send(startaddrLSB);     //Second 8 bits of the address
  
  for (char ct=0x0; ct<2; ct++)  // loop where we write info to Wire library buffer. 2 to fill up the page.
  {
    
   Wire.send(0xF2);   // Sends the value 0xF2 to Wire library buffer.
   startAddress++;
   if (startAddress >= 0x0FFF){
     Serial.print("OVERWRITE COMPLETE");
     startAddress = (-1);     // if set to zero, address is off by 1 after 1st overwrite. WHY???
     delay(5000);
   }
  }
  
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
   Serial.print(" Done3."); Serial.println(startAddress);
  
}
 



And this to read it:
Code:
// sketch to read entire chip 32 bytes at a time, display on serial monitor with progress indicated.
// Aug2010- Volkemon tweaked and commented for use with 24LC32a for Danm
//      _ _
//  A0-|oU |-Vcc
//  A1-|   |-WP
//  A2-|   |-SCL
// Vss-|   |-SDA
//      ---
//
//   SDA goes to Arduino 4
//   SCL goes to Arduino 5
//   WP  goes to ground for now. Can be put to Vcc if write protection is needed.
//   Vcc goes to arduino Vcc
//   Vss goes to arduino ground
//   A2, A1, A0 go to ground for now.
//
// They can be also put to either ground or Vcc to control up to 8 memory chips (2^3), giving you 2MBit of memory (8*2^15).
// A2 A1 A0 Binary Address Hex Address
// 0  0  0    0b1010000       0×50
// 0  0  1    0b1010001       0×51
// 0  1  0    0b1010010       0×52
// 0  1  1    0b1010011       0×53
// 1  0  0    0b1010100       0×54
// 1  0  1    0b1010101       0×55
// 1  1  0    0b1010110       0×56
// 1  1  1    0b1010111       0×57
  
#include <Wire.h>

char chipAdress=0x54;        // Binary 10100000 . Three bits after 1010 (currently 000) are used to specify to what A2, A1, A0 are connected to, ground or vcc. See comment above.
                      // Last bit specifies the opertation - 0 for write, 1 for read. This is controlled for you by the Wire library. :)
int block = 0;



void setup()

{
  Wire.begin();           // enable the i2c bus
  Serial.begin(9600);   // Did you set your serial monitor to 9600?
  Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the beginning of memory

  Wire.send(0x00);      
  Wire.send(0x00);    
  
  Wire.endTransmission(); // sends Wire buffer to chip, sets Internal Address Pointer to '0'
  
  
}

void loop()
{
  Serial.println("");
  Serial.print(block);
  Wire.requestFrom(chipAdress, 32);          // requests 32 Bytes of data in a packet, maximum string size.
  while(Wire.available()){                // 'while loop' start, Checks to see if data is waiting
    Serial.print("  ");                  // space to format packets on serial monitor
    Serial.print(Wire.receive(), HEX);  // print the values received on the serial monitor
  }                                    // end bracket for 'while loop'
  Wire.endTransmission();           // when 'while loop' is finished (no more data available) 'closes' chip
  //Serial.println("");
  block += 1;
  if (block > 128){
    Serial.println("End Of Memory");
    delay(5000);
  }
  delay(100);
}
 

Both sketches compile, but I have no 24LC32a to try them on. See if they work for you.






15  Forum 2005-2010 (read only) / Interfacing / 24LC256 Page Wrap Writing errors. on: July 25, 2010, 11:04:48 am
Recently got the 24LC256 from sparkfun, and wanted to incude it in a current project I am working on. I was having problems with corrupted and missing data, however.

From the datasheet-
Quote
Page write operations are limited to writing
bytes within a single physical page,
regardless of the number of bytes actually
being written. Physical page boundaries
start at addresses that are integer
multiples of the page buffer size (or 'page
size') and end at addresses that are
integer multiples of [page size – 1]. If a
Page Write command attempts to write
across a physical page boundary, the
result is that the data wraps around to the
beginning of the current page (overwriting
data previously stored there), instead of
being written to the next page, as might be
expected. It is, therefore, necessary for the
application software to prevent page write
operations that would attempt to cross a
page boundary.

To summarize as I understand it presently, corrections welcome!!

 The memory in the 24LC256 is set up in pages. These pages are 64 Bytes in size. This makes the starting address of the first page 0x0000 and the last address on the first page is 0x003F. The second page starts at 0x0040, and finishes at  0x007F. Third is 0x0080 to 0x00BF and so on.

If you set the Internal Address Pointer close to the end of one of the pages, and attempt to [glow]write[/glow] past it, it DOES NOT continue on to the beginning of the next page as one might expect. It wraps around to the beginning of that page and overwrites the data there.

Now... if you set the Internal Address Pointer close to the end of one of the pages, and attempt to [glow]read[/glow] past it, it DOES continue on to the beginning of the next page as one might expect. There is no page wrap.

I cobbled this together to demonstrate-
Code:
// Some code to demonstrate 'page wrap' that occurs on writing past certain address points on a 24LC256.
// mashup from Volkemon 7/2010



#include <Wire.h>  


char chipAdress=0x50;   // 24LC256 address on the bus, pins a0,a1 and a2 tied to ground.

int pacs = 30;  // variable to control how many Bytes are read/written per string. Decimal Value!! Set to desired value for test,minimum value is 1.
                // Maximum is 31 due to <Wire.h> library resrtriction. Any data written after that will be lost, without error message.


char startaddr = 0x14; // variable to set start address in memory we are writing to.   HEX value!!!    maximum value is FF.
                       // 64= 0x40, 63=0x3F, 50=0x32, 40=0x28, 30=0x1E, 20=0x14, etc
                       // http://www.easycalculation.com/decimal-converter.php   Decimal to HEX converter tool and more.

                  



void setup()

{
  Wire.begin();             // enable the i2c bus
  Serial.begin(19200);      // Make sure you set the serial monitor to match! :)
}



void loop()
{

  Serial.print("Writing starting at bite/slot "); Serial.print(startaddr, DEC);  // info sent to serial monitor for debugging.
  Wire.beginTransmission(chipAdress);    // chip address on the TWI bus, not chip memory address.
  
                  //Set up the chip Internal Address Pointer to the desired location
  Wire.send(0x00);          //First  7 bits of the address (max value 7F, BTW :)  Make sure you change it below also if you change this!!
  Wire.send(startaddr);     //Second 8 bits of the address set in the beginning, set above.

  
  for (char ct=0x0; ct<pacs; ct++)  // loop where we write info to Wire library buffer.
  {
    
   Wire.send(ct);   // Sends the value of 'ct' to Wire library buffer.
                    // 'ct' is the increment count to 'pacs'. Makes the wrap point easy to detect.
  
  }
  Wire.endTransmission();      // commands write of data from Wire library buffer to chip , 'closes' chip
  
  Serial.println(" Done.");


  Serial.print("Reading from bite/slot "); Serial.print(startaddr, DEC);
  Wire.beginTransmission(chipAdress); // chip address on the TWI bus, not chip memory address.
  
                      //Set up the chip Internal Address Pointer and start reading where you started writing before
                      
  Wire.send(0x00);           //First  7 bits of the address in chip memory  (max value 7F, BTW :)
  Wire.send(startaddr);          //Second 8 bits of the address in chip memory, (set in the beginning).
  Wire.endTransmission();    // sends data from Wire library buffer to chip, setting chip Internal Address Pointer
  
                                    
  Wire.requestFrom(chipAdress, pacs);         // from chipAdress (bus address of chip) , Wire requests 'pacs' number of packets in a string.
  
  while(Wire.available()){                // 'while loop' start, Checks to see if data is waiting
    Serial.print("  ");                  // space to format packets on serial monitor
    Serial.print(Wire.receive(), HEX);  // print the values received in hexadecimal format on the serial monitor. FF is the page wrap.
  }                                    // end bracket for 'while loop'
  
  Wire.endTransmission();           // when 'while loop' is finished (no more data available) 'closes' chip and removes it from the bus.
  
  Serial.println("");
  delay(1000);
}


Using the code above, you can change the start address of where you write a 30 Byte sting to chip memory. It is set to start at address 0x1E (dec 20) and write a 30 character string.

Opening the serial monitor, you will see a write notice, "Done", and then a read notice, then the data that results. Note that the count is linear.

Now go into the code and change 'startaddr' to 0x28 (dec 40). This will cause out 30 byte message to go over the end of the page. Now upload the change, and open the serial monitor.

Opening the serial monitor, you will see a write notice, "Done", and then a read notice, then the data that results. Note that the count is linear up to the 14th value, then returns FF. This is because the page wrap caused the write to go to the beginning of the page, and the read goes on to the next page unaffected.  
(EDIT* I say it returns the value FF above..if you have a virgin 24LC256! If you already have data written, it will be listed instead. The break in the linear progression will alert you to the page break, however.)

THIS simple fact was causing great problems in my datalogger project, as data gets corrupted as Page Wraps happen on a somewhat random basis. This was when I used a simple counter to advance the Internal Address Pointer from the software. I now realize that there must be some sort of check to see if the start address is too close to a 'page end' to write the desired data without causing a Page Wrap.

I am looking towards organizing the data written to the 24LC256 in a 30 byte packet, increment the 'startaddr' by 2, and so on. This should make the beginning of a page be the start address every other data string, and only 'waste' 4 bytes per page.

I have read that the Wire.library allows for 32 byte strings, but I can only put the variable 'pacs' to 30. It will read 31 or 32 bytes at once, but will only seem to write 30. No error sent upon the inability to write the last two bytes either.


Thats where I am now. Any help or advice is appreciated!
  
Pages: [1] 2