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

Need help to understand include file

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








Need help to understand include file
PostPosted: Sat Oct 15, 2005 9:37 am     Reply with quote

I want to read data from a 24LC128. I'm using the include file 24128.
My code hangs in my for loop:
Also, after reading data sheet and lots of other people's code here, I don't understand where in the include file the contents of the address are advanced.
-I thought a pointer would be needed here?
-I also don't understand why shifting 5 (not 4, not 8) bits?
-Also can someone tell me what significance is this number - #define EEPROM_SIZE 16384
-What controls the timing of the eeprom?

The following is an excerpt from the include file 24128- where do the contents of the address advance?
Code:
byte read_ext_eeprom(long int address) {
   byte data;
   i2c_start();
   i2c_write(((0xa0)|(hi(address)>>5))&0xfe);
   i2c_write(hi(address)&0x3f);
   i2c_write(address);
   i2c_start();
   i2c_write((0xa1)|(hi(address)>>5));
   data=i2c_read(0);
   i2c_stop();
   return(data);
}


And here's my code where it hangs in the for loop, just after the LED blinks. I only need to read a long file from the memory, only writing to send control bits. ps. I can't access a scope until Monday.
Code:
#include <16F877.H>
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP    // changed to HS for 20 mHz
#use delay(clock=20000000)                           // adjust for resonator frequency
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)           // set up options (pic is master + pinouts)
#include <LCD_16f877A.c>
#use standard_io(c)
#use fast_io(a)
#include <24128.c>
//test eeprom
      int hex, i;
      int test;
      long int address;
      main()
      {
      lcd_init();
      setup_adc_ports(NO_ANALOGS);
      setup_adc(ADC_OFF);
      disable_interrupts(global);
      init_ext_eeprom();
      i2c_start();                                  // built in function to start
      output_high (PIN_A0);                         // test
      output_low (PIN_A0);                          // test       
      i2c_write(0xA1);                              // send control byte to eeprom 'read'
      i2c_start();                                  // restart to read

       for (i=0; i<50; i++)                         // this loop = # bytes in hex file "hex"
       {
       hex = read_ext_eeprom(0x00);           //what I think I am doing here is reading the contents of the eeprom starting at address 0000
       output_high (PIN_A0);                        // init test
       printf(lcd_putc,"\feeprom", hex);         // test LCD
       output_low (PIN_A0);                         // LED off
       }
      }


Any help/advice thank you!
SophE
Ttelmah
Guest







PostPosted: Sat Oct 15, 2005 10:05 am     Reply with quote

If you want the address to 'advance', _you_ advance it. The driver just accesses the specified address.
You don't need to access the I2C controls themselves. Just use the read routine on it's own. It already sends the address, and starts/stops the transaction.
So:
Code:

       for (i=0; i<50; i++)   // this loop = # bytes in hex file "hex"
       {
       hex = read_ext_eeprom(i);           //read from address 'i'
       output_high (PIN_A0);                        // init test
       printf(lcd_putc,"\feeprom", hex);         // test LCD
       output_low (PIN_A0);                         // LED off
       }


Get rid of your own I2C code in the initialisation, and it should work.

Best Wishes
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