-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
pic Help me: insect bite is really itchy what can I do?
By Steven P.,
- 9 replies
- 1,703 views
-
- 10 replies
- 2,777 views
-
- 3 replies
- 3,484 views
-
- 8 replies
- 7,974 views
-
- 0 replies
- 4,498 views
-
Question
n_K
I've been having a bit of a proble with a PIC (18F4520) controlling a DS1307 RTC via IIC and communicating with a PC over RS232...
I've got these 2 functions;
{
unsigned char Data;
IdleI2C();
StartI2C();
WriteI2C(DeviceAddress & 0xFE);
IdleI2C();
WriteI2C(Position);
IdleI2C();
RestartI2C();
WriteI2C(DeviceAddress | 1);
IdleI2C();
while (SSPSTATbits.RW == 1) { }
Data = ReadI2C();
IdleI2C();
NotAckI2C();
StopI2C();
I2C_Pointer = Position;
++I2C_Pointer;
return Data;
}
unsigned char I2C_Read()
{
//Reads data from I2C Device
unsigned char Data;
IdleI2C();
StartI2C();
WriteI2C(DeviceAddress | 1);
IdleI2C();
while (SSPSTATbits.RW == 1) { }
Data = ReadI2C();
IdleI2C();
NotAckI2C();
StopI2C();
++I2C_Pointer;
return Data;
}
Now I'm really not understanding why but for some darned reason I'm not able to get I2C_Read() working properly, when I run it I get back one byte, and instead of the internal pointer inside the RTC going up by one (say from 0x00 to 0x01) it will only go up by two, so from 0x00 to 0x02! This happens even if I comment out the NotAckI2C(); and have the protocol exactly as the DS1307 specification says, and I can't seem to understand why?
When I use the first function and specify the address, it works absolutely fine.
Write: 01, 02, 03, 04, 05, 06, 07, 08, 09
Top function gets: 01, 02, 03, 04, 05, 06, 07, 00, 09
Second function gets: 01 or 02, 04, 06, etc.
IIC registers are all setup fine.
Link to comment
Share on other sites
12 answers to this question
Recommended Posts