View previous topic :: View next topic |
Author |
Message |
gdrarun
Joined: 30 Jun 2017 Posts: 12
|
External eeprom issue [Solved] |
Posted: Mon Sep 11, 2017 8:37 pm |
|
|
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
|
|
Posted: Mon Sep 11, 2017 11:01 pm |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Sep 12, 2017 5:03 am |
|
|
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
|
|
Posted: Tue Sep 12, 2017 6:06 am |
|
|
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
|
|
Posted: Tue Sep 12, 2017 6:53 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Sep 12, 2017 7:21 am |
|
|
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 |
|
|
|