Two problems with SX-B & SX48
Hi,
I think I've found two problems with the SXB compiler v. 1.51.03 when used with the SX48 chip.
First problem:
The I2CSTOP function modifies the data direction register of the port associated with the SDA and SCL lines.
Example:
SDA var ra.0
SCL var ra.1
The function I2CSTOP SDA may randomly change the direction of the lines RA.2 and RA.3
This happens because the compiled code loads the tris_a register with the value in __PARAM1.
Suggested workaround:
Initialize __PARAM1 with the value of the tris_a register before calling I2CSTOP
e.g.
__param1 = tris_a
I2CSTOP SDA
Second problem:
The interrupt routine does not preserve the value of __PARAMCNT (which shares the register __PARAM5).
As a result, if, from the interrupt, you call a subroutine with a variable number of parameters, you can get unexpected results from your code.
Suggested workaround:
Use the following code:
INTERRUPT NOCODE
ASM
CLR FSR
MOV __INTPARAMFSR,__PARAM1
MOV __INTPARAMFSR+1,__PARAM2
MOV __INTPARAMFSR+2,__PARAM3
MOV __INTPARAMFSR+3,__PARAM4
MOV __INTPARAMFSR+4,__PARAM5 ;
ENDASM
BANK
....your interrupt code
ASM
CLR FSR
MOV __PARAM1,__INTPARAMFSR
MOV __PARAM2,__INTPARAMFSR+1
MOV __PARAM3,__INTPARAMFSR+2
MOV __PARAM4,__INTPARAMFSR+3
MOV __PARAM5,__INTPARAMFSR+4
ENDASM
RETURNINT
I think I've found two problems with the SXB compiler v. 1.51.03 when used with the SX48 chip.
First problem:
The I2CSTOP function modifies the data direction register of the port associated with the SDA and SCL lines.
Example:
SDA var ra.0
SCL var ra.1
The function I2CSTOP SDA may randomly change the direction of the lines RA.2 and RA.3
This happens because the compiled code loads the tris_a register with the value in __PARAM1.
Suggested workaround:
Initialize __PARAM1 with the value of the tris_a register before calling I2CSTOP
e.g.
__param1 = tris_a
I2CSTOP SDA
Second problem:
The interrupt routine does not preserve the value of __PARAMCNT (which shares the register __PARAM5).
As a result, if, from the interrupt, you call a subroutine with a variable number of parameters, you can get unexpected results from your code.
Suggested workaround:
Use the following code:
INTERRUPT NOCODE
ASM
CLR FSR
MOV __INTPARAMFSR,__PARAM1
MOV __INTPARAMFSR+1,__PARAM2
MOV __INTPARAMFSR+2,__PARAM3
MOV __INTPARAMFSR+3,__PARAM4
MOV __INTPARAMFSR+4,__PARAM5 ;
ENDASM
BANK
....your interrupt code
ASM
CLR FSR
MOV __PARAM1,__INTPARAMFSR
MOV __PARAM2,__INTPARAMFSR+1
MOV __PARAM3,__INTPARAMFSR+2
MOV __PARAM4,__INTPARAMFSR+3
MOV __PARAM5,__INTPARAMFSR+4
ENDASM
RETURNINT
Comments
· Thank you for letting me know about these.
· The __PARAM5 problem has already been fixed, but the I2CSTOP bug is a new find.
· The "MOV FSR,#__PARAM1" should be omitted.
·I will make sure it is fixed in the next release.
Thanks again,
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
·The next time you need a hero don't look up in the sky...Look in the mirror.
·
Paolo