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

At24c128/256
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

At24c128/256
PostPosted: Sat Jan 30, 2010 4:37 pm     Reply with quote

I am using Pic16f886 and want to use At24c128 external epprom.
I am using i2c but could get any answer from At24c128.

I pull up scl and sda with 100k, and all address pins to gnd.

My compiler is PCM and Version 4.068.
Code:

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3

#use i2c(MASTER, sda=PIN_C4,scl=PIN_C3)

void init_ext_eeprom()
{
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);
}

BOOLEAN ext_eeprom_ready() {
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0xA0);  // then the device is ready.
   i2c_stop();
   return !ack;
}

void main()
{
   disable_interrupts(GLOBAL);   
   
   output_a(0b00000000);
   output_b(0x00);
   output_c(0b00011000);
   output_e(0x00);
   
   set_tris_a(0b00000000);
   set_tris_b(0x00);
   set_tris_c(0b00011000);
   set_tris_e(0x00);

        init_ext_eeprom();
   delay_ms(2);
        while(!ext_eeprom_ready()); // could not pass this test

       // my code does not come here
}

I used above code could not success. Anybody used to before At24c128.
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jan 30, 2010 5:11 pm     Reply with quote

Quote:
I pull up scl and sda with 100k

1K is standard I2C pull-up, 10K will possibly work, 100K most likely won't.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sat Jan 30, 2010 5:23 pm     Reply with quote

FvM wrote:
Quote:
I pull up scl and sda with 100k

1K is standard I2C pull-up, 10K will possibly work, 100K most likely won't.


Thanks for your comment. Before 100k I tried 10k but result was same.

Do you think my code is true? Do you have another idea ?
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 30, 2010 11:53 pm     Reply with quote

Use this driver:
Quote:

c:\program files\picc\drivers\24256.c

Make a test program similar to the one shown in this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=30346&start=10
Change the #define statements to use your own i2c pins.

Change the pull-up resistors to 4.7K ohms.

Don't use inline driver routines, as in your original post. Include the
24256.c eeprom driver with an #include statement, as shown in the link
above. Call the driver routines from main().
Ttelmah
Guest







PostPosted: Sun Jan 31, 2010 4:14 am     Reply with quote

What processor?.
This affects whether you are using hardware I2C, or software.
Are you operating a 5v version, or a 3.3v version. What voltage is your system?.
Is the WP pin grounded as well?. Since you are trying to get an ACK, from a 'write' operation, I'm not sure this will be acknowledged, if the WP pin is high...

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 4:55 am     Reply with quote

Quote:
Since you are trying to get an ACK, from a 'write' operation, I'm not sure this will be acknowledged, if the WP pin is high...

It will.
Quote:
When Write Control (WC) is driven High, Device Select and Address bytes are acknowledged, Data bytes are not acknowledged.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 7:32 am     Reply with quote

FvM wrote:
Quote:
Since you are trying to get an ACK, from a 'write' operation, I'm not sure this will be acknowledged, if the WP pin is high...

It will.
Quote:
When Write Control (WC) is driven High, Device Select and Address bytes are acknowledged, Data bytes are not acknowledged.


Please find attached image file and get more detailed information about my design.

I am using Pic 16f886 and Vcc = 5v
also wp connected to GND.

http://www.zumodrive.com/share/3mXpYzE2Yz

I could not tried 24256.c driver and could not pull up 4.7k but I will try as soon as possible.
But I am intersting that 24c256.c driver and 4.7k pull up appropriate to At24c128/256.

Also I am using these configuration
Code:

#include "16f886.h"
#device *=16 ADC=10
#use delay(clock=8000000)   // 8MHz Clock

Is it important to use internal oscillator with 8 Mhz or 4 Mhz ?

Code:

#fuses INTRC,NOWDT,NOMCLR,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT,NOCPD, NODEBUG

// set up  internal oscillator

setup_oscillator(OSC_8MHZ,0);   //set oscillator to 8Mhz

Does it make sense ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 8:05 am     Reply with quote

It seems like the compiler is using software I2c by default. You can try with hardware I2C by adding
FORCE_HW to the #use i2c statement.

I don't see a particular problem with your code or hardware.

You should also mention the compiler version.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 10:59 am     Reply with quote

FvM wrote:
It seems like the compiler is using software I2c by default. You can try with hardware I2C by adding
FORCE_HW to the #use i2c statement.

I don't see a particular problem with your code or hardware.

You should also mention the compiler version.


My compiler is PCM and Version 4.068.
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site
Ttelmah
Guest







PostPosted: Sun Jan 31, 2010 11:28 am     Reply with quote

0=ACK.
In C, 0=true
So your function, returns ext_eeprom_notready (since you invert your ACK bit). Then you invert this again, so will wait if the chip _does_ acknowledge.....

Best Wishes
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 12:42 pm     Reply with quote

Ttelmah wrote:
0=ACK.
In C, 0=true
So your function, returns ext_eeprom_notready (since you invert your ACK bit). Then you invert this again, so will wait if the chip _does_ acknowledge.....

Best Wishes


I prepared my code according to your suggestion but result was same. My code could not pass below control. Could not read which I wrote.
Code:

write_ext_eeprom(0x01, 0xAA);
data = read_ext_eeprom(0x01);   
    
if(data == 0xAA)
  {
   BlinkRed();
   Beep(2000);   
  }

I do not understand what is different between hardware i2c and software i2c. I tried hardware i2c like FORCE_HW but my software is frozen.

Tomorrow I will change my hardware pull up resistor 100k to 4.7k.

Any other relevant suggestion ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 1:20 pm     Reply with quote

Post your test program, similar to this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=30346&start=10
Do not post the 24256.c driver. Only post your test program.

The test program must be complete, and must compile with no errors.
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 1:35 pm     Reply with quote

PCM programmer wrote:
Post your test program, similar to this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=30346&start=10
Do not post the 24256.c driver. Only post your test program.

The test program must be complete, and must compile with no errors.


This is my latest code.
//main.h

Code:

#include "16f886.h"
#device *=16 ADC=10
#use delay(clock=8000000)   // 8MHz Clock

#fuses INTRC,NOWDT,NOMCLR,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT,NOCPD, NODEBUG

#include "main.h"

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(E)

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3

#include <24256.c>

#define BUZZER      PIN_C2

void Beep(int delay)
{
   output_high(BUZZER);
   delay_ms(delay);
   output_low(BUZZER);
}

void main()
{
   BYTE data;
   
   output_a(0x00);
   output_b(0x00);
   output_c(0b00011000);
   output_e(0x00);
   
   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0b00011000);
   set_tris_e(0x00);   

   setup_oscillator(OSC_8MHZ,0);   //set oscillator to 8Mhz
   
      init_ext_eeprom();
   delay_ms(2);
   write_ext_eeprom(0, 0x55);
   data = read_ext_eeprom(0);   
    
   if ( data == 0x55 )
      {
      Beep(50);
   }
   while(1);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 2:17 pm     Reply with quote

Try a more simple program, as shown below. Also make sure you have
the correct connections:
Pin C4 on the PIC connects to the SDA pin on the At24c128.

Pin C3 on the PIC connects to the SCL pin on the At24c128.

The Vss pin (ground) on the PIC connects to the GND pin on the At24c128.

Also, notice the order of the first 3 statements. The #use delay()
comes after the #fuses. If you do it this way, the compiler will
automatically setup the correct oscillator configuration. Then you
don't need to use the setup_oscillator() statement.
Code:

#include <16F886.h>
#fuses INTRC_IO,NOWDT,NOMCLR,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=8000000)   

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#include <24256.c>

#define BUZZER  PIN_C2

void Beep(int delay)
{
output_high(BUZZER);
delay_ms(delay);
output_low(BUZZER);
}

//============================
void main()
{
int8 data;
   
init_ext_eeprom();
write_ext_eeprom(0, 0x55);
data = read_ext_eeprom(0);   
     
if(data == 0x55)
  {
   Beep(500);  // Beep once if data is correct
  }
else
  {
   Beep(500);   // Beep 3x if not correct
   delay_ms(500);
   Beep(500);
   delay_ms(500);
   Beep(500);
  }

while(1);
}
muratmaman



Joined: 30 Jan 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jan 31, 2010 2:37 pm     Reply with quote

PCM programmer wrote:
Try a more simple program, as shown below. Also make sure you have
the correct connections:
Pin C4 on the PIC connects to the SDA pin on the At24c128.

Pin C3 on the PIC connects to the SCL pin on the At24c128.

The Vss pin (ground) on the PIC connects to the GND pin on the At24c128.

Also, notice the order of the first 3 statements. The #use delay()
comes after the #fuses. If you do it this way, the compiler will
automatically setup the correct oscillator configuration. Then you
don't need to use the setup_oscillator() statement.
Code:

#include <16F886.h>
#fuses INTRC_IO,NOWDT,NOMCLR,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=8000000)   

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#include <24256.c>

#define BUZZER  PIN_C2

void Beep(int delay)
{
output_high(BUZZER);
delay_ms(delay);
output_low(BUZZER);
}

//============================
void main()
{
int8 data;
   
init_ext_eeprom();
write_ext_eeprom(0, 0x55);
data = read_ext_eeprom(0);   
     
if(data == 0x55)
  {
   Beep(500);  // Beep once if data is correct
  }
else
  {
   Beep(500);   // Beep 3x if not correct
   delay_ms(500);
   Beep(500);
   delay_ms(500);
   Beep(500);
  }

while(1);
}


Thanks for your effort but software could not pass this line

write_ext_eeprom(0, 0x55);

In this line code frozen.
_________________
I have been developing pic and other microcontroller. I would want to share and get experiment form this site


Last edited by muratmaman on Sun Jan 31, 2010 2:38 pm; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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