Compass module and I2C bus


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what happened to your results when you change to a Byte Sized variable? you should read something between 0-255

    NOW if you want to use a word sized variable, YOU MUST READ register #2, not 1, so try...
    Code:
    ControlByte VAR BYTE
    Register VAR BYTE
    ControlByte = $C0
    Register = 2
    '
    '
    '
    '
    i2cread dpin,cpin,ControlByte,Register,[bearing.highbyte, bearing.lowbyte]
    and you should read something in a range of 0-3599
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1249&stc=1&d=116582183 1">

    About now?
    Attached Images Attached Images  
    Last edited by mister_e; - 11th December 2006 at 07:30.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Big Thank You Mister E.
    You and MELABs staff helped me to find mistake. I insert in my code two lines and now program works great. These are two lines:
    DEFINE I2C_HOLD 1
    DEFINE I2C_SLOW 1

    Maybe, someone will have the same problems in future, so I decided to post all my code. It works flawless.
    Thanks again
    Vladimir

    'PIC16f872
    '---------------- Definitions---------------------------------------------
    define OSC 20
    '------------- Define LCD registers and bits------------------------------
    DEFINE I2C_HOLD 1
    define I2C_SLOW 1
    Define LCD_DREG PORTB 'Set LCD data port
    Define LCD_DBIT 0 'Set starting data bit
    Define LCD_RSREG PORTB 'Set LCD register select port
    Define LCD_RSBIT 4 'Set LCD register select bit
    Define LCD_EREG PORTB 'Set LCD enable port
    Define LCD_EBIT 5 'Set LCD enable bit
    define DEBUG_REG PORTC 'Set DEBUD port
    DEFINE DEBUG_BIT 1 'Set DEBUG pin
    DEFINE DEBUG_BAUD 2400 'Set DEBUG baud rate
    DEFINE DEBUG_MODE 0 'Set DEBUG mode



    DPIN var PORTc.4 ' I2C data pin
    CPIN var PORTc.3 ' I2C clock pin
    bearing var word ' word size bearing value 0 - 359
    bearing1 var byte ' byte size bearing value 0 - 255

    Main:
    i2cread dpin,cpin,%11000000,2,[bearing.Highbyte,bearing.lowbyte]

    lcdout $fe, 1,"BEARING ",DEC BEARING/10

    i2cread dpin,cpin,%11000000,1,[bearing1]

    lcdout $fe, $c0,"Bearing ", dec bearing1

    DEBUG " Compass Bearing ", # bearing,13,10

    pause 20

    goto main

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nice!

    Now forward the info to Devantech
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Cool

    DONE. I mailed Info to Devantech.
    Best Wishes.
    Vlad

  5. #5
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Hi guys!

    Well ! i have some confusions in understanding the following program :

    1) what is the purpose and function of this line :

    DEBUG " Compass Bearing ", # bearing,13,10

    2) Why is the address be written as %11000000?

    3) WHat is the function of this line:

    i2cread dpin,cpin,%11000000,2,[bearing.Highbyte,bearing.lowbyte]

    4) and what this DEC sign means, i have checked the help section, it is no command. Then why it is written there :

    lcdout $fe, 1,"BEARING ",DEC BEARING/10


    lcdout $fe, $c0,"Bearing ", dec bearing1

    Please help me as soon as possible!

    and can anyone tell me whats the cost of this CMPS-03?

    Can we operate it through I2C on PIC16F84A?
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

  6. #6
    Join Date
    Jul 2006
    Location
    Surrey, BC, Canada
    Posts
    31


    Did you find this post helpful? Yes | No

    Wink

    Hello shaiqbashir!

    I will try to give you answers.
    1) what is the purpose and function of this line :
    DEBUG " Compass Bearing ", # bearing,13,10

    This is optional line, for development purposes only. It is sends “bearing” value serially to a terminal. In my program this command sends serial string to PORT_C, pin No1, baud rate 2400.

    2) Why is the address be written as %11000000?

    This is address designated by Devantech (Devantech is company producing the compass module)

    3) WHat is the function of this line:

    i2cread dpin,cpin,%11000000,2,[bearing.Highbyte,bearing.lowbyte]
    Function of this line is reading "bearing" value through I2C bus, as WORD size variable.


    4) and what this DEC sign means, i have checked the help section, it is no command. Then why it is written there :

    lcdout $fe, 1,"BEARING ",DEC BEARING/10
    lcdout $fe, $c0,"Bearing ", dec bearing1

    DEC means decimal. This is not command, this is modifier, it is similar to # sign and gives ASCII representation of value sending to LCD.

    and can anyone tell me whats the cost of this CMPS-03?

    http://www.robotshop.ca/home/product...le-cmps03.html

    Can we operate it through I2C on PIC16F84A?

    Why not? In my application I use PIC 16F872 because 16F84A has limited amount of ports (pins).
    Best regards Vlad

  7. #7
    Join Date
    Apr 2006
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Many Many Thanks Mr. Vladimir

    please tell me the following two points as well!

    1) Which type of LCD screen have u used. Can i use an LCD screen with three terminals (+5V, GND, control) using Serout command? What lcd u have used?

    2) On each PIC, it is usually written that which is the SDA pin and which is the SLA one. While when i was reading the diagram of PIC16F84A , it was not mentioned. According to you , i can use this I2C on PIC16F84A, is it possible that we can use any two pins for I2C operation? or are there always two fixed pins dedicated for it?

    I shall be looking for ur precious reply!

    Take carez!

    Good Bye!
    LETS MOVE TOWARDS SOMETHING PRACTICAL---

Similar Threads

  1. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  2. Oscillator stops when touching with a wire
    By Wilbert Ingels in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 25th April 2008, 08:51
  3. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  4. I2C Comm with Digital Compass HMC6352
    By jihlein in forum Serial
    Replies: 10
    Last Post: - 9th April 2008, 22:25
  5. I2C compass - Philips KMZ51
    By barkerben in forum General
    Replies: 0
    Last Post: - 25th December 2005, 20:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts