|
|
View previous topic :: View next topic |
Author |
Message |
karth
Joined: 10 Sep 2003 Posts: 29
|
pic30f4013, i2c problem |
Posted: Tue Oct 28, 2008 1:19 pm |
|
|
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);
}
} |
|
|
|
karth
Joined: 10 Sep 2003 Posts: 29
|
|
Posted: Tue Oct 28, 2008 1:37 pm |
|
|
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 |
|
|
|
|
|
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
|