PROPBASIC and the I2C commands...
denno
Posts: 223
Bean, I am stumped...the following is the code that is running in COG 7. It is written for the HMC6352 compass module from Sparkfun.
and I get the following ERROR message, that I do not understand...
PropBasic Version 00.01.48 Aug 9, 2018
Finished Compile. 435 Lines Read, 1989 Lines Generated, 0 Warnings, 0 Errors.
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Win32 at 08:17:48 on 2009/07/20
Loading Object LCDdisplay_SE
Loading Object LCD_1.spin
Loading Object longDistSensor.spin
Loading Object compass.spin
Loading
Object volt_measure.spin
Loading Object LED_blink.spin
Loading Object blinkAnotherLED.spin
Loading Object sonicDistance.spin
LCDdisplay_SE(177,41) Error : Unresolved Symbol - HMC6352_compass_COG
mov __temp1,HMC6352_compa
Thanks..DennO
TASK HMC6352compass 'RUNNING IN COG 2 HMC6352_data PIN 0 HMC6352_clk PIN 1 HMC6352_read CON $43 HMC6352_WRITE CON $42 GET_HEADING CON $41 heading_HIGH_byte VAR LONG heading_LOW_byte VAR LONG I2C_data VAR LONG I2C_lsb VAR LONG valueSTR HUB string (4) ackbitvar VAR LONG ackbitvalue VAR LONG compass_get_heading SUB I2C_ACK SUB I2C_NACK SUB '---------[Main Routine]--------------- DO GOSUB compass_get_heading valueSTR = STR heading_HIGH_byte,4, 5 SEROUT 30, baud2, 1 SEROUT 30, baud2, 10 SEROUT 30, baud2, valueSTR PAUSE 100 LOOP SUB compass_get_heading I2CSTART HMC6352_data,HMC6352_clk I2C_DATA = HMC6352_WRITE I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA, ackbitvar I2C_DATA = GET_HEADING I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA, ackbitvar I2CSTOP HMC6352_data, HMC6352_clk PAUSE 10 I2CSTART HMC6352_data,HMC6352_clk I2C_DATA = HMC6352_READ I2CWRITE HMC6352_data, HMC6352_clk, I2C_DATA, ackbitvar PAUSE 10 ' Give the HMC6352 time to calculate the rawHeading I2CREAD HMC6352_data, HMC6352_clk, I2C_DATA, ackbitvalue heading_HIGH_byte = I2C_DATA ' Read in the high byte GOSUB I2C_ACK I2CREAD HMC6352_data, HMC6352_clk, I2C_DATA, ackbitvalue heading_LOW_byte = I2C_DATA ' Read in the low byte GOSUB I2C_NACK I2CSTOP HMC6352_data, HMC6352_clk ENDSUB ' SUB I2C_ACK LOW HMC6352_data ' Pull HMC6352_data low INPUT HMC6352_clk ' Let HMC6352_clk float high LOW HMC6352_clk ' Pull HMC6352_clk low INPUT HMC6352_data ' Let HMC6352_data float high ENDSUB ' SUB I2C_NACK INPUT HMC6352_data ' Let HMC6352_data float high INPUT HMC6352_clk ' Let HMC6352_clk float high LOW HMC6352_clk ' Pull HMC6352_clk low ENDSUB ENDTASK HMC6352 '======================================================
and I get the following ERROR message, that I do not understand...
PropBasic Version 00.01.48 Aug 9, 2018
Finished Compile. 435 Lines Read, 1989 Lines Generated, 0 Warnings, 0 Errors.
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Win32 at 08:17:48 on 2009/07/20
Loading Object LCDdisplay_SE
Loading Object LCD_1.spin
Loading Object longDistSensor.spin
Loading Object compass.spin
Loading
Object volt_measure.spin
Loading Object LED_blink.spin
Loading Object blinkAnotherLED.spin
Loading Object sonicDistance.spin
LCDdisplay_SE(177,41) Error : Unresolved Symbol - HMC6352_compass_COG
mov __temp1,HMC6352_compa
Thanks..DennO
Comments
The only thing that jumps out at me is that you should not put the task name after ENDTASK. But I don't think that would cause an error, but it might confuse the compiler.
You don't need to generate the ACK and NACK signal as a separate step. They are generated or received by the normal I2CREAD and I2CWRITE commands.
Bean
Now, the program loads, and compiles. But I am not getting an accurate reading from the HMC6352, meaning the "heading_HIGH_byte" does not change from 255 and the "heading_LOW_byte" only changes a few degrees one way or the other. So, my question is...is there some sort of COMMAND that needs to go between the two "I2CREAD(s)". I have included the code below for your inspection. And, does it make a difference which byte is read first, the HIGH or LOW byte? I added the "I2CSPEED" to see if it makes a difference, but it doesn't seem too. Adding the HIGH and LOW byte should give the heading...?
Thanks again Bean, for your time, as I suspect that you are a very busy person, much appreciated...\
DennO
Any suggestions....thanks...DennO
I would assume it has to be zero, a one will probably abort the transfer.
I don't see where you set it to any value...
Also, Why are you always using I2C_DATA instead of just putting the value or variable directly in the I2CREAD or I2CWRITE line ?
And there is no reason to use ackbitvar if you are not going to look at what it's value is...Just leave it off.
Bean
DennO