Looks like a hardware master I2C routine. You know there are examples of both hardware and software I2C routines in the contributors section of the forum?
Looking at your first ack_nack routine your results are not what you think. The Set SSPCOM.ACKDT On never occurs if ack_nack = 0. Maybe use seperate ack's or nack's as required,
Think the BANKSEL SYSCALCTEMPA stuff is just GCBasic doing the math routines.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I know routines in the contributors section.
But I make function(see below).
So, I change "if statement" as below.
-----------------------------------------------
function RxI2C(ack_nack) ' =1:ACK =0:NACK
WaitforI2CisIdle
Set PIR1.SSPIF Off
Set SSPCON2.RCEN On 'Initiate reception
do
loop until SSPSTAT.BF On
RxI2C = SSPBUF 'Read byte in buffer
Set PIR1.SSPIF Off
if ack_nack = 1 then Set SSPCON2.ACKDT Off 'Send acknowledge
if ack_nack = 0 then Set SSPCON2.ACKDT On 'Send no acknowledge
Set SSPCON2.ACKEN On 'Select to send ACK/NACK
do
loop until SSPCON2.ACKEN Off
end function
-------------------------------------------------------------------
and 2nd prog. changed like below
--------------------------------------
do
loop until (SSPCON2 and 0x1F)=0
do
loop until SSPSTAT.2 Off
---------------------------------------
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
finaly I changed as below
------------------------------------------
function RxI2C(ack_nack) ' =1:ACK =0:NACK
WaitforI2CisIdle
Set PIR1.SSPIF Off
Set SSPCON2.RCEN On 'Initiate reception
do
loop until SSPSTAT.BF On
RxI2C = SSPBUF 'Read byte in buffer
Set PIR1.SSPIF Off
if ack_nack = 1 then SendACKI2C : else SendNACKI2C
Set SSPCON2.ACKEN On 'Select to send ACK/NACK
do 'Check if operation complete
loop until SSPCON2.ACKEN Off
end function
'-----------
sub SendACKI2C
Set SSPCON2.ACKDT Off 'Send acknowledge
end sub
' ----------
sub SendNACKI2C
Set SSPCON2.ACKDT On 'Send no acknowledge
end sub
That's worked fine.
Thanks
-----------------
P.S.
2nd prog. worked.
I use "mikroBASIC(free trial)" , "Swordfish (BASIC) compiler SE" and SDCC.
and use Tiny Bootloader.
and have PIC16F88, PIC16F873A, PIC16F877A, PIC18F2550
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. I'm Japanese.
I compile and download. But do't work.
I installed ver.0.9.3.0
and updated by update.zip
source code
........
if ack_nack = 1 then
Set SSPCON2.ACKDT Off
else
Set SSPCON2.ACKDT On
end if
........
object code
................
010C 3001 00385 MOVLW 1
010D 0220 00386 SUBWF ACK_NACK,W
010E 1D03 00387 BTFSS STATUS, Z
010F 2914 00388 GOTO ELSE1_1
0110 1683 1303 00389 BANKSEL SSPCON2
0112 1291 00390 BCF SSPCON2,ACKDT
0113 2915 00391 GOTO ENDIF1
0114 00392 ELSE1_1
0114 1691 00393 BSF SSPCON2,ACKDT
0115 00394 ENDIF1
................
is this incorrect???
anothor case is below
BANKSEL for SYSCALCTEMPA (after select SSPSTAT)
source code
..........
do
loop until (((SSPCON2 and 0x1F)=0) and (SSPSTAT.2 = 0))
..........
object code
...............
011B 00407 SYSDOLOOP_S4
011B 301F 00408 MOVLW 31
011C 1683 1303 00409 BANKSEL SSPCON2
011E 0511 00410 ANDWF SSPCON2,W
011F 1283 1303 00411 BANKSEL SYSTEMP1
0121 00C2 00412 MOVWF SYSTEMP1
0122 00B1 00413 MOVWF SYSCALCTEMPA
0123 01B3 00414 CLRF SYSCALCTEMPB
0124 2251 00415 CALL SYSCOMPEQUAL
0125 0835 00416 MOVF SYSCALCTEMPX,W
0126 00C4 00417 MOVWF SYSTEMP2
0127 01B1 00418 CLRF SYSCALCTEMPA
0128 1683 1303 00419 BANKSEL SSPSTAT
012A 1914 00420 BTFSC SSPSTAT,2
012B 1283 1303 00421 BANKSEL SYSCALCTEMPA
012D 0AB1 00422 INCF SYSCALCTEMPA,F
012E 01B3 00423 CLRF SYSCALCTEMPB
012F 2251 00424 CALL SYSCOMPEQUAL
0130 0835 00425 MOVF SYSCALCTEMPX,W
0131 00C2 00426 MOVWF SYSTEMP1
0132 0844 00427 MOVF SYSTEMP2,W
0133 0542 00428 ANDWF SYSTEMP1,W
0134 00C5 00429 MOVWF SYSTEMP3
0135 1C45 00430 BTFSS SYSTEMP3,0
0136 291B 00431 GOTO SYSDOLOOP_S4
0137 00432 SYSDOLOOP_E4
..............
Welcome to the forum.
Looks like a hardware master I2C routine. You know there are examples of both hardware and software I2C routines in the contributors section of the forum?
Looking at your first ack_nack routine your results are not what you think. The Set SSPCOM.ACKDT On never occurs if ack_nack = 0. Maybe use seperate ack's or nack's as required,
Think the BANKSEL SYSCALCTEMPA stuff is just GCBasic doing the math routines.
Thanks for replay.
I know routines in the contributors section.
But I make function(see below).
So, I change "if statement" as below.
-----------------------------------------------
function RxI2C(ack_nack) ' =1:ACK =0:NACK
WaitforI2CisIdle
Set PIR1.SSPIF Off
Set SSPCON2.RCEN On 'Initiate reception
do
loop until SSPSTAT.BF On
RxI2C = SSPBUF 'Read byte in buffer
Set PIR1.SSPIF Off
if ack_nack = 1 then Set SSPCON2.ACKDT Off 'Send acknowledge
if ack_nack = 0 then Set SSPCON2.ACKDT On 'Send no acknowledge
Set SSPCON2.ACKEN On 'Select to send ACK/NACK
do
loop until SSPCON2.ACKEN Off
end function
-------------------------------------------------------------------
and 2nd prog. changed like below
--------------------------------------
do
loop until (SSPCON2 and 0x1F)=0
do
loop until SSPSTAT.2 Off
---------------------------------------
Thanks
above change has error still.
finaly I changed as below
------------------------------------------
function RxI2C(ack_nack) ' =1:ACK =0:NACK
WaitforI2CisIdle
Set PIR1.SSPIF Off
Set SSPCON2.RCEN On 'Initiate reception
do
loop until SSPSTAT.BF On
RxI2C = SSPBUF 'Read byte in buffer
Set PIR1.SSPIF Off
if ack_nack = 1 then SendACKI2C : else SendNACKI2C
Set SSPCON2.ACKEN On 'Select to send ACK/NACK
do 'Check if operation complete
loop until SSPCON2.ACKEN Off
end function
'-----------
sub SendACKI2C
Set SSPCON2.ACKDT Off 'Send acknowledge
end sub
' ----------
sub SendNACKI2C
Set SSPCON2.ACKDT On 'Send no acknowledge
end sub
That's worked fine.
Thanks
-----------------
P.S.
2nd prog. worked.
I use "mikroBASIC(free trial)" , "Swordfish (BASIC) compiler SE" and SDCC.
and use Tiny Bootloader.
and have PIC16F88, PIC16F873A, PIC16F877A, PIC18F2550
Thanks.