Shop OBEX P1 Docs P2 Docs Learn Events
HMC6352 and PROPBASIC — Parallax Forums

HMC6352 and PROPBASIC

Has anyone written a PROPBASIC program to run the HMC6352 compass module...?
DennO

Comments

  • dennodenno Posts: 219
    edited 2018-09-24 14:19
    Bean, good morning...I am working with your I2C commands, and I am wondering if your can define the following for me with a little more detail. Again, I am trying to make the HMC6352 compass module work....with PROPBASIC
    1. what is the ACKBITVALUE
    2. what is the ACKBITVAR
    3. and, I cannot seem to put more then "one" GOSUB in a DO/LOOP, with getting the error MESSAGE of "SUN OR FUNCTION CANNOT BE NESTED". In other words, one GOSUB in a loop will work, but two or more GOSUB's will not....
    4. Where should I put the I2SPEED command to slow down the PROP...

    Do you have any examples of code..

    Thank you...DennO
  • BeanBean Posts: 8,129
    1. ACKBITVALUE is the ack bit value that you want to send to the slave (0 or 1). Normally it is 0.
    2. ACKBITVAR is a variable that receives the ack bit from the slave (0 or 1). Again normally it is 0.
    3. You do not need GOSUB, just put the subroutine name. You are probably using SUB when you are calling. Don't do that...
    4. If you use the built-in I2C commands they will run at the proper speed.

    Looking at the datasheet you just send a "A" then wait a bit and read back two bytes.

    I2CStart
    I2CWrite $42
    I2CWrite 65
    I2CStop
    PAUSE 10
    I2CStart
    I2CWrite $43
    I2CRead
    I2CRead
    I2CStop

    Bean
  • Not having any success getting the HMC6352 working with I2C and PROPBASIC. Have tried several "angles and adjustments" to the code, with no joy...below is the code that I have been playing with.
    DEVICE P8X32A, XTAL1, PLL8X
    XIN 5_000_000
    
    '========CONSTANTS============
    baud2                  CON "T115200" 
    HMC6352_READ           CON      $43
    HMC6352_WRITE          CON      $42
    GET_HEADING_command    CON      $41
    '========[PIN ASSIGNMENTS]==========
    'Assignments of pin go in each COG that is using that pin..
      HMC6352_data  PIN     3
      HMC6352_clk   PIN     4
    '========[VARIABLES]===========================
      valueSTR2          HUB       string (3)
      valueSTR           HUB       string (3)
      I2C_DATA           VAR       LONG
      rawHeading1        VAR       LONG
      rawHeading2        VAR       LONG
      rawHeadingTOT      VAR       LONG
      ACKbitVar          VAR       LONG
    
    PROGRAM Start  'this is running in COG 0
      Start:
      
     DO
    '  I2CSPEED .5'''''''multipier
      I2CSTART HMC6352_data, HMC6352_clk
      pause 10
      I2C_DATA = HMC6352_WRITE
      I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA
      pause 10
      I2C_DATA = GET_HEADING_command
      I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA
      pause 10
      I2CSTOP HMC6352_data, HMC6352_clk
      PAUSE 10
      I2CSTART HMC6352_data, HMC6352_clk
      pause 10
      I2C_DATA = HMC6352_READ
      I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA
      PAUSE 10                                   ' Give the HMC6352 time to calculate the rawHeading
      I2CREAD HMC6352_data, HMC6352_clk, I2C_DATA, 0'''ackbitvalue'''''''SDAPin, SCLPin, var, ackbitvalue
      pause 10
      rawHeading1 = I2C_DATA                           'HIGHBYTE Read in the high byte
      valueSTR2 = STR rawHeading1,3,5
      SEROUT 30, baud2, valueSTR2
      SEROUT 30, baud2, 10
      SEROUT 30, baud2, 13
      I2CREAD HMC6352_data, HMC6352_clk,I2C_DATA, 0'''ackbitvalue'''''''SDAPin, SCLPin, var, ackbitvalue
      pause 10
      rawHeading2 = I2C_DATA                           'LOWBYTE Read in the low byte
      valueSTR = STR rawHeading2, 3,5
      SEROUT 30, baud2, valueSTR
      SEROUT 30, baud2, 10
      I2CSTOP HMC6352_data, HMC6352_clk
    PAUSE 100
    LOOP
    END
    

    I would like to add that I do know that the MC6352 that I am using is good, as it runs perfect on the BS2. The above code loads with no errors, and the "screen output" only shows a "2" and then a "208", with no change when the HMC6352 is rotated.

    ANybody, any thoughts...DennO

  • BeanBean Posts: 8,129
    Try this..
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    
    '========CONSTANTS============
    baud2                  CON "T115200" 
    HMC6352_READ           CON      $43
    HMC6352_WRITE          CON      $42
    GET_HEADING_command    CON      $41
    
    '========[PIN ASSIGNMENTS]==========
    'Assignments of pin go in each COG that is using that pin..
    HMC6352_data           PIN     3
    HMC6352_clk            PIN     4
    
    '========[VARIABLES]===========================
    valueSTR2              HUB       string(4)
    valueSTR               HUB       string(4)
    
    rawHeading1            VAR       LONG
    rawHeading2            VAR       LONG
    
    PROGRAM Start  'this is running in COG 0
    
    Start:
      
     DO
      I2CSTART HMC6352_data, HMC6352_clk
      I2CWRITE HMC6352_data, HMC6352_clk, HMC6352_WRITE
      I2CWRITE HMC6352_data, HMC6352_clk, GET_HEADING_command
      I2CSTOP HMC6352_data, HMC6352_clk
    
      PAUSE 10 ' Give the HMC6352 time to calculate the rawHeading
    
      I2CSTART HMC6352_data, HMC6352_clk
      I2CWRITE HMC6352_data, HMC6352_clk, HMC6352_READ                                  
      I2CREAD HMC6352_data, HMC6352_clk, rawHeading1, 0 'HIGHBYTE Read in the high byte
      I2CREAD HMC6352_data, HMC6352_clk, rawHeading2, 1 'LOWBYTE Read in the low byte
      I2CSTOP HMC6352_data, HMC6352_clk
    
      valueSTR2 = STR rawHeading1, 3
      SEROUT 30, baud2, valueSTR2
      SEROUT 30, baud2, 10
      SEROUT 30, baud2, 13
    
      valueSTR = STR rawHeading2, 3
      SEROUT 30, baud2, valueSTR
      SEROUT 30, baud2, 10
    
      PAUSE 100
     LOOP
    END
    

    Bean
  • Sorry Bean, and thank you for your input, but all I get is the same thing....rawHeading1 = 255 and rawHeading2 = 255. I will keep snooping around...DennO
Sign In or Register to comment.