CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

EERAM Microchip 47C16 I2C not losing values when power cycle

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

EERAM Microchip 47C16 I2C not losing values when power cycle
PostPosted: Thu May 02, 2019 1:55 pm     Reply with quote

Hi All:
I just started to work with EERAM 47c16 with dsPIC33EP512MU810 using Mikro boards. I can write and read the data fine, reset the board and the data is ok. When I power off the unit and back on I lose the data.
I figured out the address to be A0 and A1, my jumpers are all 0.
Code:

// Write a byte at the address in the EEPROM new
void write_eeprom_ext(int32 address, char data)
   {
   int i;
   char datar;
   int32 address2;
   unsigned int8 addresshi;
   unsigned int8 addresslo;
   unsigned int8 write_ext;
   unsigned int8 read_ext;
   unsigned int8 ack;
   //does the value need to be changed
   datar= read_eeprom_ext(address);
   if(datar==data)
   {
       return; //data is the same no write needed
   }
   write_ext=0xA0;
   read_ext=0xA1;
   address2=address;//&0x7FFFF;// force address consistency
   while (address2>=0x20000)
   {
          address2-=0x20000;// chip address space
          write_ext+=2;    // next chip
          read_ext+=2;
   }
   if(address2>=0x10000)// block address space
   {
          address2-=0x10000;
          write_ext+=8; // second block in the chip
          read_ext+=8;
   }
 
   addresslo=(address2);
   address2>>=8;
   addresshi=(address2);
   eeprom_errors_flag=1;
   for (i=0;i<3;i++)
   {
      i2c_start(I2C_INT);
      i2c_write(I2C_INT,write_ext);
      i2c_write(I2C_INT,addresshi); //upper address
      i2c_write(I2C_INT,addresslo); //lower address
      i2c_write(I2C_INT,data);
      i2c_stop(I2C_INT);
      ack=1;   // EEPROM does not ACK when not ready
      while(ack&(i<100))
      {
        i2c_start(I2C_INT);
        ack=i2c_write(I2C_INT,write_ext); // ACK will end the loop (active low)
        i2c_stop(I2C_INT);
        i++;
      }
    i2c_start(I2C_INT);
    ack=i2c_write(I2C_INT,write_ext); // ACK will end the loop (active low)
      i2c_write(I2C_INT,addresshi); //upper address
      i2c_write(I2C_INT,addresslo); //lower address
      i2c_start(I2C_INT);
      i2c_write(I2C_INT,read_ext);
      datar=i2c_read(I2C_INT,0);     
      i2c_stop(I2C_INT);
      if(data==datar){
            eeprom_errors_flag=0;
           break;
        }
      }

   }
// Read a byte from address in EEPROM new
char read_eeprom_ext(int32 address)
{
   char data;
   int32 address2;
   unsigned int8 addresshi;
   unsigned int8 addresslo;
   unsigned int8 write_ext;
   unsigned int8 read_ext;
   //load lowest locations
   write_ext=0xA0;
   read_ext=0xA1;
  address2=address;//&0x7FFFF;// force address consistency
   while (address2>=0x20000)
   {
          address2-=0x20000;// chip address space
          write_ext+=2;    // next chip
          read_ext+=2;
   }
   if(address2>=0x10000)// block address space
   {
          address2-=0x10000;
          write_ext+=8; // second block in the chip
          read_ext+=8;
   }
   addresslo=(address2);
   address2>>=8;
   addresshi=(address2);
   i2c_start(I2C_INT);
   i2c_write(I2C_INT,write_ext);
   i2c_write(I2C_INT,addresshi);
   i2c_write(I2C_INT,addresslo);
   i2c_start(I2C_INT);
   i2c_write(I2C_INT,read_ext);
   data=i2c_read(I2C_INT,0);   
   i2c_stop(I2C_INT);
   
   return(data);
}

The part I do not understand is the HW (Hardware) and the Control bytes(code). Shocked http://ww1.microchip.com/downloads/en/DeviceDoc/20005371C.pdf

Please advice me thank you..
asmallri



Joined: 12 Aug 2004
Posts: 1630
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu May 02, 2019 4:25 pm     Reply with quote

I cannot tell form the code snippet you have posted, Brownout Detect needs to be enabled to force the PIC into reset as the power supply rails drop when power is removed. This will prevent the PIC from crashing and running amok as the supply rail voltage collapses.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: EERAM Microchip 47C16 I2C not losing values when power c
PostPosted: Thu May 02, 2019 7:05 pm     Reply with quote

David Pouzar wrote:
Hi All:
I just started to work with EERAM 47c16 with dsPIC33EP512MU810

The eeram is a 5v part, whereas the dsPIC is a 3.3v part. You should be
using the 47L04 since it's a 3.3v part.
avro698



Joined: 11 Nov 2006
Posts: 9
Location: South Wales, UK.

View user's profile Send private message

PostPosted: Fri May 03, 2019 3:49 am     Reply with quote

Hi,

I'm using 47L16 at 3.0V without issue.
To clarify, does your hardware have a capacitor on the VCAP pin? (this is needed for autostore function on power removal).

This device has two groups of addresses; one for normal ram access, the other for control.
Normal eeprom actions use device addresses 0xA0/0xA1 (plus whatever value you have for A1 and A0).
Control of the device is via device addresses 0x30/0x31 (plus whatever value you have for A1 and A0).

To get the device to autostore on power removal you need to set the ASE (bit 1) of the STATUS register (Explanation on page 15 of the datasheet you linked to). I believe this is zero by default (the datasheet is not very clear in this regard). This register is non-volatile so you only need to set ASE once.

So to enable autostore something like this is required on the I2c bus; <write command address>,<access status register>,<set ASE bit> or; 0x30,0x00,0x02

Hope that helps.

Regards,

avro698
David Pouzar



Joined: 20 Sep 2005
Posts: 27

View user's profile Send private message Visit poster's website

PostPosted: Fri May 03, 2019 6:28 am     Reply with quote

Thank you for the help. I am using a i2c at 5 volts.. Yes I have the cap on the board. I am actually using Mikroe board eeram 5v. The problem was fixed by initialize the chip like avro recommended. Thank you..
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Sat May 04, 2019 1:44 am     Reply with quote

Quote:

I am using a i2c at 5 volts.


How?.

Show your I2C setup code, and the wiring you have for the I2C bus.

Understand, that if I2C is being pulled up to 5v, the PIC pins will
be overvoltaged, and be limiting the voltage with their internal protection
diodes, risking the PIC supply being raised and overvoltaging the PIC.

The 47C16 requires Vih to be > 0.7Vcc, so 3.5v. Above the voltage
that can be generated with 3.3v pullups.

This is a combination that really _requires_ a level shifter between
the two busses.

Look at the FET level shifter in this AN:
<https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=13&cad=rja&uact=8&ved=2ahUKEwjo2_b-r4HiAhWlunEKHa_mBKUQFjAMegQIAhAC&url=https%3A%2F%2Fwww.nxp.com%2Fdocs%2Fen%2Fapplication-note%2FAN10441.pdf&usg=AOvVaw2Tvfiswb6hEumO5qUyIgPV>

You _need_ something like this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group