I made another test, with TMR4 interrupt at every 40 us and now system crash !
Janni , please explain me, why cI2C_wr is function in your code example ?
I2c_Rd or I2c_Wr blocking when interrupted.
Thanks, you saved me some effort .yo2lio wrote:I made another test, with TMR4 interrupt at every 40 us and now system crash !
It's a reconstruction of original ME's function from assembly (with the bug fixed, naturally), not an example . Check it's description in help - it's supposed to be a function.Janni , please explain me, why cI2C_wr is function in your code example ?
Re:
Hello
I know this is old topic, but could someone translate this code to mikroBasic?
Thank you
I know this is old topic, but could someone translate this code to mikroBasic?
Thank you
janni wrote:Code: Select all
function cI2C_rd(ack:byte): byte; begin PIR1.SSPIF:=0; SSPCON2.RCEN:=1; while PIR1.SSPIF=0 do begin end; result:=SSPBUF; SSPCON2.ACKDT:=0; if ack<>0 then SSPCON2.ACKDT:=1; PIR1.SSPIF:=0; SSPCON2.ACKEN:=1; while PIR1.SSPIF=0 do begin end; End;{cI2C_rd} function cI2C_wr(data:byte): byte; begin PIR1.SSPIF:=0; SSPBUF:=data; while PIR1.SSPIF=0 do begin end; if SSPCON2.ACKSTAT=0 then result:=0 else begin SSPCON2.PEN:=1; result:=2; end; End;{cI2C_wr} procedure cI2C_Stop; begin SSPCON2.PEN:=1; End;{cI2C_Stop}
Re: I2c_Rd or I2c_Wr blocking when interrupted.
You do not really need it as mE corrected I2C library since then, but here you are
Code: Select all
sub function cI2C_rd(dim ack as byte) as byte
PIR1.SSPIF=0
SSPCON2.RCEN=1
while PIR1.SSPIF=0 wend
result=SSPBUF
SSPCON2.ACKDT=0
if ack<>0 then SSPCON2.ACKDT=1 end if
PIR1.SSPIF=0
SSPCON2.ACKEN=1
while PIR1.SSPIF=0 wend
end sub 'cI2C_rd
sub function cI2C_wr(dim data as byte) as byte
PIR1.SSPIF=0
SSPBUF=data
while PIR1.SSPIF=0 wend
if SSPCON2.ACKSTAT=0 then result=0
else
SSPCON2.PEN=1
result=2
end if
end sub 'cI2C_wr
sub procedure cI2C_Stop
SSPCON2.PEN=1
end sub 'cI2C_Stop
Re: I2c_Rd or I2c_Wr blocking when interrupted.
janni, thank you very much for your code.
I'm using older version of mikroBasic compiler, and I have same problem as title of this thread.
I will try your code and I hope I can solve the problem.
Thanks again.
I'm using older version of mikroBasic compiler, and I have same problem as title of this thread.
I will try your code and I hope I can solve the problem.
Thanks again.