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

pic30f4013, i2c problem

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



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

pic30f4013, i2c problem
PostPosted: Tue Oct 28, 2008 1:19 pm     Reply with quote

The problem is that i2c is not functioning properly, can anyone could see what I am doing wrong ? I verified the circuit and it is fine....

Here is my code:
Code:
#use i2c(Master,sda=PIN_F2,scl=PIN_F3, FORCE_HW, SLOW) // hw I2C

#define MAXREC 2370
#define MEM_MAIN   8
#define EEPROM_SDA                     PIN_F2
#define EEPROM_SCL                      PIN_F3

void init_ext_eeprom()
{
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);

}


void write_ext_eeprom(int memaddr, BYTE dat,int8 HWADDR1)
{
   
   i2c_start();
   i2c_write((0xa0|HWADDR1)&0xfe);    // control byte
   i2c_write(memaddr>>8);
   i2c_write(memaddr);
   i2c_write(dat);
   i2c_stop();
   delay_ms(5);
   init_ext_eeprom();
}


BYTE read_ext_eeprom(int address,int8 HWADDR1)
{
   BYTE data;

   i2c_start();
   i2c_write((0xa0|HWADDR1)&0xfe);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1|HWADDR1);
   data=i2c_read(0);
   i2c_stop();
   delay_ms(10);
   init_ext_eeprom();
   return(data);
}



void main()
{
int8 datatemp;
   setup_wdt(WDT_OFF);
   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
   set_tris_f(0x1f);
   init_ext_eeprom();
   while(TRUE)
   {
   write_ext_eeprom(2,'K',MEM_MAIN);
   delay_ms(1000);
   datatemp=read_ext_eeprom(2,MEM_MAIN);
   delay_ms(1000); 
   } 
}

Embarassed Embarassed
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 1:37 pm     Reply with quote

When I change to ( FORCE_SW) shown as below, it works.
Is that a bug or else???
Code:
#use i2c(Master,sda=PIN_F2,scl=PIN_F3, FORCE_SW) // hw I2C
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