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

write_ext_eeprom

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



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

write_ext_eeprom
PostPosted: Tue Feb 20, 2007 4:03 pm     Reply with quote

Hi Everyone,

Does anyone have any idea why the following simple code would not work?

Code:
#include <18F8722>
#include <24515.c>
#include <stdlib.h>
#include <math.h>

#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=2400, xmit=PIN_A4, rcv=PIN_A5, stream=PC, ERRORS)

#define LED PIN_F0

void main(void)
{
   short int c=5;
   long address=10;

   
   
   while(1)
   {
      fputc('a', PC);
      delay_ms(50);

      init_ext_eeprom();
      WRITE_EXT_EEPROM(address, c);
      delay_ms(50);
      fputc('*', PC);
               
   }

} // end of main


It prints an "a" and waits there.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 4:09 pm     Reply with quote

Follow standard debugging procedures. Comment out lines of code
until you find out which line is causing the problem.
Vefa



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 4:30 pm     Reply with quote

write_ext_eeprom line does not work. I checked my hardware. Am I missing something in the code?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 4:49 pm     Reply with quote

Do you have pull-up resistors on the each of the SDA and SCL lines ?
You need them for i2c. You can use 4.7K.

Also, I noticed something else about your program.
Quote:
short int c=5;

Did you know that in CCS, a 'short' is a 1-bit variable ?

Download the CCS manual and look at page 23 (page 33 in the Acrobat
reader). It shows a table with the sizes of the data types.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Vefa



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 8:06 pm     Reply with quote

Thanks PCM programmer. I have the pull ups. I used int instead of short int. Thanks for the manual as well. Do you agree that I have a hardware problem? or should I try low level programming as in

Code:
i2c_start();
   i2c_write(control_byte | WRITE); // write
   i2c_write(high_byte);
   i2c_write(low_byte);
   i2c_start(); // restart
   i2c_write(control_byte | READ); // read
   low_byte = i2c_read(0); // no ack
   i2c_stop();
   return (low_byte);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 8:41 pm     Reply with quote

What PIC pins are you using for the EEPROM ?

What value of resistors are you using for the pull-ups ?
Vefa



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

PostPosted: Wed Feb 21, 2007 10:19 am     Reply with quote

C3, and C4. Pull-ups are 4K. I tried 3 different 24FC515 EEPROM chips. I did a continuity test. Everything in the hardware end seems to be in good /working condition. I am using a friend's circuit and he successfully used the circuit with a similar code. Still, I can't get the code that I initially posted to work. I am a newbie and I am not sure if I am missing a very simple thing.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 22, 2007 2:27 pm     Reply with quote

Post your compiler version. I'll compile the code and look at the .LST file.
Vefa



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

PostPosted: Fri Feb 23, 2007 9:07 am     Reply with quote

My compiler is PCH version 3.249.
When I compile the code with the compiler on my friend's computer, it works! When I compile it with mine it does not. We have the same compiler. I am going to try reinstalling the compiler. Any suggestion?
Ttelmah
Guest







PostPosted: Fri Feb 23, 2007 9:18 am     Reply with quote

I posted about this quite recently.
There is a problem with certain chips, when using the hardware I2C, and a 'repeated start' command. For some reason, on these, the ACK never gets seen, and the driver will hang. Either use the software I2C (FORCE_SW), or add a 'I2C_STOP', before the restart.

Best Wishes
Vefa



Joined: 13 Feb 2007
Posts: 9

View user's profile Send private message

works!
PostPosted: Fri Feb 23, 2007 9:47 am     Reply with quote

I checked the lst file. I saw the following statement:
Code:
#ifndef EEPROM_SDA
.................... 
.................... #define EEPROM_SDA  PIN_B1
.................... #define EEPROM_SCL  PIN_B0


My sda and scl pins are C3 & C4. I then realized if I defined the sda and scl pins before including the 24515.c file then it would work. That's what I did. Following is the code that works:
Code:
#include <18F8722>
#include <stdlib.h>
#include <math.h>

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

#define LED PIN_F0

#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)


main()
{
   // EEPROM
   long address=0;

   output_high(LED);
   delay_ms(1500);
   output_low(LED);

   while(1)
   {      
      
         if(address<65535>255) output_high(LED);
         else output_low(LED);
   }
} // end of main


Thanks to everyone.
Special thanks to PCM Programmer.
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