For Bean or anyone that uses PROPBASIC...
denno
Posts: 223
Having trouble with I2C in PROPBASIC with the HMC6352 compass from Sparkfun. In PBASIC I do this, and it works.
The problem I'm having in PROPBASIC is joining the HIGHBYTE and LOWBYTE, as seen in the code below: Adding "heading1" and "heading2" does not work.
Any words of wisdom. I am using the FLIP module..thanks to all
HMC6352: (Not all GOSUB's are displayed. 'first read GOSUB I2C_Start ' Start communications on the I2C buss I2C_DATA = HMC6352_WRITE GOSUB I2C_Write ' Address the HMC6352 in write mode I2C_DATA = GET_HEADING_command GOSUB I2C_Write ' Send the get rawHeading command PAUSE 10 GOSUB I2C_Stop ' End communications on the I2C buss PAUSE 10 GOSUB I2C_Start ' Start communications on the I2C buss I2C_DATA = HMC6352_READ GOSUB I2C_Write ' Address the HMC6352 in read mode PAUSE 10 ' Give the HMC6352 time to calculate the rawHeading GOSUB I2C_Read rawHeading.HIGHBYTE = I2C_DATA ' Read in the high byte GOSUB I2C_ACK GOSUB I2C_Read rawHeading.LOWBYTE = I2C_DATA ' Read in the low byte GOSUB I2C_NACK GOSUB I2C_Stop ' End communications on the I2C buss PAUSE 10 rawHeading = rawHeading / 10 'whole degrees ' DEBUG DEC4 ? rawheading RETURN
The problem I'm having in PROPBASIC is joining the HIGHBYTE and LOWBYTE, as seen in the code below: Adding "heading1" and "heading2" does not work.
SUB compass_get_heading I2CSPEED 1 I2CSTART HMC6352_data,HMC6352_clk I2CWRITE HMC6352_data, HMC6352_clk, HMC6352_WRITE PAUSE 10 I2CWRITE HMC6352_data, HMC6352_clk, GET_HEADING PAUSE 10 I2CSTOP HMC6352_data, HMC6352_clk PAUSE 10 I2CSTART HMC6352_data,HMC6352_clk I2CWRITE HMC6352_data, HMC6352_clk, HMC6352_READ PAUSE 10 I2CREAD HMC6352_data, HMC6352_clk, heading_HIGH_byte, 0 PAUSE 10 ' Give the HMC6352 time to calculate the rawHeading I2CREAD HMC6352_data, HMC6352_clk, heading_LOW_byte, 1 PAUSE 10 I2CSTOP HMC6352_data, HMC6352_clk PAUSE 10 heading1 = heading_LOW_byte heading2 = heading_HIGH_byte ENDSUB
Any words of wisdom. I am using the FLIP module..thanks to all
Comments
heading2 = heading2 * 256
heading1 = heading1 + heading2
heading1 should now contain the correct value.
Bean
What does the I2CSPEED do exactly. Do I really need the "PAUSE 10's" in the SUB routine?
Anyone got a HMC6352 for sale....?