Did Hi2cSetup syntax change in PE6?

Pongo

Senior Member
I've used variations of Peter Anderson's 20X2 + Melexis MLX90614 IR sensor code successfully in several projects but now I want to modify one of them and PE6 is choking on a syntax error:

Code:
Hi2cSetup I2CMaster, 45, I2CSlow, I2CByte 
                                             ^
Syntax error on line 38 at/before position 45

Error: Please use full 8 bit slave address (with bit0 clear)
Why am I getting this error now when the projects are working with this code? Could it be because I originally used PE5 and now have PE6?

Full code from phanderson.com follows:

Code:
' MLX90614_1.Bas
'
' Continually measures and displays T_ambient and T_object.
'
' PICAXE-20X2               MLX90614ESF-AAA
'
' Term 11 SCL --------------- SCL
' Term 13 SDA --------------- SDA
'
' 4.7K resistors to +5 VDC on SDA and SCL
'
' Note that this is a direct interface with the PICAXE.  The Parallax and
' Sparkfun boards are not required.
' 
' copyright, Peter H Anderson, Baltimore, MD, Mar 12, 11

#picaxe 20x2
#Terminal 9600
#No_Table
#No_Data
#freq m4

Symbol Lo = B0
Symbol Hi = B1
Symbol PEC = B2
Symbol Status = B3
Symbol Whole = B4
Symbol Fract = B5
Symbol Val = W3
Symbol TC_100 = W4
Symbol SlaveAdr_2 = B10
Symbol RamLocation = B11
Symbol X = B12
Symbol N = B13
Symbol CRC8 = B14

Top:

    Hi2cSetup I2CMaster, 45, I2CSlow, I2CByte 

    SlaveAdr_2 = $00 * 2 ' use general slave adr

Again:

    RamLocation = $06 ' ambient temperature

    GoSub ReadRAM
    If Status = 1 Then
       TC_100 = Val * 2 - 27315
       SerTxD ("T_ambient = ") 
       GoSub DisplayTc
       
    Else
       SerTxD ("T_ambient - Error")
    End If

    SerTxD (",  ")

    RamLocation = $07 ' ambient temperature

    GoSub ReadRAM
    If Status = 1 Then
       TC_100 = Val * 2 - 27315
       SerTxD ("T_object = ") 
       GoSub DisplayTc
    Else
       SerTxD ("T_object - Error")  
    End If
      
    SerTxD (CR, LF)

    Pause 1000
    GoTo Again

ReadRAM:
      
    Hi2cin [SlaveAdr_2], RamLocation, (Lo, Hi, PEC)

    Val = Hi
    Val = Val * 256 + Lo
   
    'SerTxD ("Hello ", #TC_100, "  ", #PEC, CR, LF)
                        
    CRC8 = $00
    X = SlaveAdr_2
    GoSub CalcCRC8
    X = RamLocation
    GoSub CalcCRC8
    X = SlaveAdr_2 + 1
    GoSub CalcCRC8
    X = Lo
    GoSub CalcCRC8
    X = Hi
    GoSub CalcCRC8
    X = PEC
    GoSub CalcCRC8

    'SerTxD ("CRC = ", #CRC8, CR, LF)
    If CRC8 = 0 Then
       Status = 1 ' success
    Else
       Status = 0
    Endif
    
    Return

DisplayTc:

    Whole = TC_100 / 100
    Fract = TC_100 // 100

    SerTxD (#Whole, ".")
    If Fract < 10 Then
        SerTxD ("0")
    Endif
    SerTxD (#Fract)

    Return
   
CalcCRC8:

   X = X ^ CRC8
   For N = 0 to 7
      If X > 127 Then
         X = X * 2
         X = X ^ $07
      Else
         X = X * 2
      Endif
   Next
   CRC8 = X
   Return
 

Pongo

Senior Member
Confirmed! I re-installed PE5 and no syntax error.

How do I fix the code so it works with PE6?
 

Jeremy Harris

Senior Member
Confirmed! I re-installed PE5 and no syntax error.

How do I fix the code so it works with PE6?
There's clearly nothing wrong with the code, as it works when compiled properly with PE5. I have to say that, following many trials, tribulations and a fair bit of frustration with PE6 I've now deleted it and reverted to only ever using PE5. PE6 is just more trouble than its worth for every project I've tried with it, which is a great disappointment knowing that a lot of time and hard work to develop. I feel a bit disloyal reverting to PE5, but it is just so much easier to use, and reliable, than PE6 that there is really no contest between them.

The only slight snag with PE5 is that it may not support newer devices, which is a shame, but in my case just keeps me working with devices it does support. If anything PE6 is suffering because PE5 had evolved to work extremely reliable. I find PE6 less easy to use, and this combined with the very reliable and well-understood attributes of PE5 makes PE5 my favourite, by a long way.

Recently I've been coding in a plain text editor and programming chips via the command line. I've been doing this by necessity, following a switch to Linux, but it can be made to work remarkably well with a bit of creativity. I'm tempted to create a specialised text editor that organises source code neatly (not hard, as I think it can be done with macros) and then use a simple script to execute the command line compiler and programme the chip. It doesn't look that hard to do.
 

AllyCat

Senior Member
Hi,

Yes, sadly, I also still "prefer" to use PE5 most of the time.

But I believe the issue here is the lsb of the slave address (which is automatically set by the PE as Read/Write as appropriate).

The "old" Manual 2 (as used with PE5) states that "Bit0 is the read/write bit and so ignored." However, the "new" on-line command reference (which includes PE6 "improvements") says "Bit0 is the read/write bit and must be set to 0".

Your code appears to be using a slave address 45 which probably needs to be changed to 44. But later in the code, I noticed a X = SlaveAdr_2 + 1 which may need to be changed to +2 . So the PE6 error handling might be rather better in catching mistakes/oversights like this.

Cheers, Alan.
 

Pongo

Senior Member
Thanks for all your comments :D

code appears to be using a slave address 45
I believe that's a clue, per the data sheet the default slave address for the device is 90/5A which is (of course) 45 shifted left. Since Peter was a smart guy the use of 45 was unlikely to be accidental so my guess is that PE5 left shifts the value supplied to Hi2cSetup such that bit 0 will be clear, and PE6 doesn't. Anyway changing it to:

Code:
Hi2cSetup I2CMaster, 90, I2CSlow, I2CByte
solves the PE6 problem.
 

Technical

Technical Support
Staff member
What nobody has mentioned so far is the 45/90 value is irrelevant and completely ignored in that code, as the sample code only ever uses SlaveAdr_2 (=0) as the slave address....

This is a compiler issue, not a PE5/PE6 issue, and results from using an out of date compiler within PE5. An 8 bit address should always have bit0 of the slave address set to 0 for the PICAXE system. Having a 1 in the bit0 position is almost always the result of trying to use (incorrectly) a 7 bit address (as in this case, the 45 is actually wrong, so the sample code is misleading) so we think the error msg displayed is correct and justified.
 

Pongo

Senior Member
What nobody has mentioned so far is the 45/90 value is irrelevant and completely ignored in that code, as the sample code only ever uses SlaveAdr_2 (=0) as the slave address....
Thanks. Just realized that and came back to post. It doesn't care so long as it's an even number, won't take 0 though.

This is a compiler issue, not a PE5/PE6 issue, and results from using an out of date compiler within PE5.
Hard for Joe user to separate the two... (I love PE6)

An 8 bit address should always have bit0 of the slave address set to 0 for the PICAXE system. Having a 1 in the bit0 position is almost always the result of trying to use (incorrectly) a 7 bit address (as in this case, the 45 is actually wrong, so the sample code is misleading) so we think the error msg displayed is correct and justified.
Yup, fair enough. I'll bet there are a lot of copies of that code in use though.
 
Top