HMC6352 and PROPBASIC

in Propeller 1
Has anyone written a PROPBASIC program to run the HMC6352 compass module...?
DennO
DennO
Comments
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
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
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
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