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

is I2C FORCE_HW compatible with status check of write ?

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

is I2C FORCE_HW compatible with status check of write ?
PostPosted: Fri May 15, 2009 1:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 15, 2009 2:12 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri May 15, 2009 2:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 15, 2009 4:41 pm     Reply with quote

There's an errata on this problem in the 18F4525. See Section 30.
One of the work-arounds is to send a stop bit.
http://ww1.microchip.com/downloads/en/DeviceDoc/80224e.pdf
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri May 15, 2009 5:03 pm     Reply with quote

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