Both PIC18F452 and PIC18F4520 use the same I2C library : I2C_c34.ppas
Following short routine work good on PIC18F4520 and don't work on PIC18F452. Problem is I2C_Is_Idle routine.
Code: Select all
procedure SI2C_Write(ee_adr : Word; ee_data : byte);
var i : byte;
begin
I2C_Start; // Issue I2C start signal
I2C_Wr($A0); // Send byte via I2C
I2C_Wr(hi(ee_adr)); // Send byte(address for EEPROM)
I2C_Wr(lo(ee_adr)); // Send byte(address for EEPROM)
I2C_Wr(ee_data); // Send data(data that will be written)
I2C_Stop; // Issue I2C stop signal
i := 0;
while i < 10 do
begin
delayms(1);
I2C_Start; // Issue I2C start signal
I2C_Wr($A0); // Send byte via I2C
if (I2C_Is_Idle) then break;
inc(i);
end;
end;
Now, from datasheet :
For PIC18F452 (refer to SSPSTAT.2) : "ORing this bit with SEN, RSEN, PEN, RCEN, or ACKEN will indicate if the MSSP is in IDLE mode."
For PIC18F4520 (refer to SSPSTAT.2) : "ORing this bit with SEN, RSEN, PEN, RCEN or ACKEN will indicate if the MSSP is in Active mode."
Has someone experience with I2C_Is_Idle and PIC18F452 ???