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 CCS Technical Support

External eeprom issue [Solved]

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



Joined: 30 Jun 2017
Posts: 12

View user's profile Send private message

External eeprom issue [Solved]
PostPosted: Mon Sep 11, 2017 8:37 pm     Reply with quote

Hi all

I am using 18F67J11 - clocked with external 4 MHz crystal and the controller runs in PLL mode - 16 MHz. I have 24AA512 EEPROM connected to the controller and I tried to check the EEPROM with 2432 driver. But the code does not run beyond
Quote:
write_ext_eeprom(0x01,0x01);

It's stuck with the ack packet. A0, A1, A2 PINS are grounded. Am I missing something? Please advise.
Code:

#include<18f67j11.h>
#include <stdio.h>
#fuses H4_SW,PROTECT,NOIESO,NOWDT
#use delay(clock=16000000)

#include <2432.c>

#define uchar unsigned char
#define uint unsigned int

#byte PORTF   = 0xF85
#bit RLY1=PORTF.1


uchar eepromValue=0;

void main()
{
setup_oscillator(OSC_16MHZ |OSC_NORMAL | OSC_PLL_ON);
set_tris_f(0x00);

   delay_ms(1000);
   init_ext_eeprom();
   RLY=1;
   write_ext_eeprom(0x01,0x01);
   RLY=0;
   eepromValue=read_ext_eeprom(0x01);
   
   if(eepromValue==0x01)
   {
      RLY=1; delay-ms(1000);
      RLY=0; delay-ms(1000);
      RLY=1; delay-ms(1000);
   }


   while(1){
      ;
      }

}





Thanks
gdrarun



Joined: 30 Jun 2017
Posts: 12

View user's profile Send private message

PostPosted: Mon Sep 11, 2017 11:01 pm     Reply with quote

Hi

Sorry! I just made it work and it was a problem with the hardware. Sorry!

Thank you all
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 12, 2017 5:03 am     Reply with quote

sometimes it's the simple things....

Whenever you're using I2C peripherals, ALWAYS run the 'I2CScanner' programmer in the code library BEFORE testing your code. It will tell you every I2C device 'on the bus' and their adresses. Makes it easy, wel easier, to get PIC projects 'up and running'.


Jay
gdrarun



Joined: 30 Jun 2017
Posts: 12

View user's profile Send private message

PostPosted: Tue Sep 12, 2017 6:06 am     Reply with quote

Hi Again

I do face a little strange problem and sorry if my understand is wrong about the subject.

I believe that the address location gets incremented automatically for each byte when page writes and reads are performed.

Please have a look at the below code.

Code:


void write_ext_eeprom_page(long int address, int chLen) {
   int epStr=0;
   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);

   for(epStr=0;epStr<chLen;epStr++)
   i2c_write(eeprom_buffer[epStr]);
 
   i2c_stop();
}



void read_ext_eeprom_page(long int address,int chLen ) {
   int epStr=0;
   byte tbuf=0;
   while(!ext_eeprom_ready());
   i2c_start();
   i2c_write(0xa0);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   
   for(epStr=0;epStr<(chLen-1);epStr++)
   {
         tbuf=i2c_read();
      eeprom_buffer[epStr]=tbuf;
   }
   tbuf=i2c_read(0);
   eeprom_buffer[epStr]=tbuf;
   eeprom_buffer[chLen]='\0';
     i2c_stop();

}




Basically I am trying to write and read a specific length of characters stored in the eeprom_buffer variable. Here comes the problem

Code:

        sprintf(eeprom_buffer,"1234567");
   write_ext_eeprom_page(0x01,7);

////////////////////// READ

        read_ext_eeprom_page(0x01,7);


Writes and reads as expected. But.....

When I try to read 3 chars from 0x01 with
Code:
read_ext_eeprom_page(0x01,3);
I get an empty string.

Quote:
read_ext_eeprom_page(0x02,2); >> EMPTY
read_ext_eeprom_page(0x01,8); >> EMPTY


Even if I try to read a single byte (0x01) from memory it returns NULL.
I have pulled up with 4k7 and is this right? Any clues? Please advise

Regards
Arun
gdrarun



Joined: 30 Jun 2017
Posts: 12

View user's profile Send private message

PostPosted: Tue Sep 12, 2017 6:53 am     Reply with quote

Hi...

Looks the the problem is in the address.....

if I comment out the following and give a static high byte and low byte... it works and I can read as many chars I want starting from address 1.

Code:
 // i2c_write(hi(address));
         // i2c_write(address);
    i2c_write(0x00);
    i2c_write(0x01);


Why this is happening? Please clarify.

Code:
#define hi(x)  (*(&x+1))
#define low(x) (*(&x))


Thank you
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 12, 2017 7:21 am     Reply with quote

this...
#define hi(x) (*((int8 *)&x+1))

is how my version of the 2432 driver computes the high byte of the address.

Yours is slightly different....


Perhaps try mine and see what happens. I recall there was a 'thread' abut this and the above code was a 'patch'.

Jay
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