|
|
View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
is I2C FORCE_HW compatible with status check of write ? |
Posted: Fri May 15, 2009 1:27 pm |
|
|
V3.249 18F4525 @ 18432000Hz
I'm using a Microchip 24LC256 chip and I'm rewriting the driver for
page write and for going across chip boundaries.
my question: is I2C FORCE_HW compatible with status check of write?
I am using the write_ext_eeprom() from 24256.c as a start.
When I change to FORCE_HW my routine locks and can't complete the write. It seems to be stuck at the status check.
If I turn off FORCE_HW then it works.
C:\Program Files\PICC\Drivers\24256.C
Code: | void write_ext_eeprom(long int address, BYTE data)
{
//parts are missing for the copyrights sake
.....stop...
i2c_start();
status=i2c_write(0xa0);
while(status==1)
{
i2c_start();
status=i2c_write(0xa0);
}
}
|
this is changed in the driver
#use i2c(master,SDA=EEPROM_SDA,SCL=EEPROM_SCL,FORCE_HW) //start with slow
Code: | //05/14/2009 9:54AM Single 24LC256 EEPROM
#define FIRM_MAJOR (int8) 'i'
#define FIRM_MINOR (int8) 8
#include <18F4525.h>
#fuses hs,nowdt,noprotect,nolvp,put
#use delay(clock=18432000,RESTART_WDT)
#use rs232(baud=19200,xmit=PIN_D7,invert,stream=DEBUG)
#case
#zero_ram
#include <STDLIB.H>
#define AddrVal 0
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#include "24256.C" //local copy of driver.. I'm messing with this
void init(void);
void init_ext_eeprom(void);
void display_binary(char c);
void write_ext_eeprom(int16 address,int8 data);
int8 read_ext_eeprom(int16 address);
void main(void)
{
int8 i,tmp;
int8 w[70];//1024 byte write array with random data
int8 r[70];//1024 byte read array with read in data
int16 addr;//array is written to and read from address
int16 cnt;//counter for setting up array
init();
init_ext_eeprom();
addr=AddrVal;
for (cnt=0;cnt<sizeof(w);cnt++) w[cnt]=rand();
for(addr=AddrVal,cnt=0;cnt<sizeof(w);cnt++,addr++)
{
write_ext_eeprom(addr,w[cnt]);
fprintf(DEBUG,".");
}
for(addr=AddrVal,cnt=0;cnt<sizeof(w);cnt++,addr++)
{
r[cnt]=read_ext_eeprom(addr);
}
for (cnt=0;cnt<sizeof(w);cnt++)
{
if(r[cnt]!=w[cnt])
{
fprintf(DEBUG,"\w\rError r=%03u w=%03u cnt=%lu\n\r",r[cnt],w[cnt],cnt);
}
}
fprintf(DEBUG,"\n\rDone!\n\r");
while(1);
}
//========================= Functions ==============================//
//=== init ===// setup the initial settings
#define BEEP PIN_C0
#define RELAY PIN_C1
#define XMTHEN PIN_C5
void init(void)
{
int8 tmp;
output_low(BEEP);
output_low(RELAY);
output_low(XMTHEN);
//set_tris_a(0xFF);set_tris_b(0xFF);set_tris_c(0xFF);set_tris_d(0xFF);set_tris_e(0xFF);
setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF);
port_b_pullups(FALSE);
fprintf(DEBUG,"Start\n\r");
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 15, 2009 2:12 pm |
|
|
Quote: |
i2c_start();
status=i2c_write(0xa0);
while(status==1)
{
i2c_start();
status=i2c_write(0xa0);
}
i2c_stop();
} |
I noticed one difference between your code and 24256.c.
CCS has an i2c_stop at the end. Your code does not. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri May 15, 2009 2:15 pm |
|
|
The stop you mentioned fixed it.
This is what I have.. Ill delete if someone could only verify it. Thanks
Ver 3.249
edit ...
snip..
or should there be a stop after the while(status==1) block of the write
Last edited by treitmey on Fri May 15, 2009 4:51 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri May 15, 2009 5:03 pm |
|
|
I did see that errata. Tried to pop in a 18F452 at about noon time to eliminate that from the equation.
...but by now my brain is mush and I don't know what was tried/eliminated or not.
I've got it working now.
Thanks |
|
|
|
|
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
|