I2CWRITE to control a I2C device


View Poll Results: Was this usefull to you

Voters
2. You may not vote on this poll
  • Yes

    2 100.00%
  • No

    0 0%
Closed Thread
Results 1 to 2 of 2
  1. #1
    bbubel's Avatar
    bbubel Guest

    Default I2CWRITE to control a I2C device

    This is a good example on using I2CWRITE to control a I2C device. Feel free to use this code for your own use.

    ' The LTC6904 is a 1kHz - 68 MHz Serial Port Programmable Oscilator
    ' the Interface is a I2C serial bus
    ' The program sweeps the frequency from 3.7 to 4.2 MHz


    define OSC 20 'Define the Osc to 20 MHz
    define I2C_SCLOUT 1

    'establish Variables
    SDA Var PORTB.0
    SCL Var PORTB.1
    freq_count vaR WORD
    lofreq var word
    I2C_out Var Word
    I2C-outlo Var I2C_out.BYTE0
    I2C-outHi Var I2C_out.BYTE1
    FREQ Var word
    b0 var freq.byte0
    b1 var freq.byte1
    '---------------------------------------------------------------

    TRISB = %00000000 ' Set PORTB to all output
    PORTB = %00000000 ' Clear PORTB
    freq = $0
    freq_count = 0
    lofreq = 0
    '---------------------------------------------------------------
    MAIN:
    gosub SET_freq
    gosub WR_freq
    Pause 1000 'Demo purpose only
    Goto Main
    stop

    '********* LTC6904 Subroutines **************************

    '---------------------------------------------------------------------
    WR_freq: 'Set the LO freq

    I2C_out = $2E 'Set LTC6904 address to 2E Hex
    I2Cwrite SDA, SCL, I2C-outlo, b1,[b0], I2C_err

    return
    I2C_err:
    stop
    '--------------------------------------------------------------------
    SET_Freq:
    freq_count = freq_count+10 'Increment 10.5KHz
    lofreq = 860 + freq_count 'Offset 3.66 Mhz
    lofreq = lofreq << 2 'Shift left 2 bits
    Freq = lofreq | $B002 ' Bitwise "OR" with OCT (1011) and CNF(10)
    if freq_count < 150 then exit '3.7 to 4.2 MHz
    freq_count = 0
    exit:
    return
    '************************************************* ***
    '

    end

  2. #2
    bbubel's Avatar
    bbubel Guest

    Unhappy oops

    Variables I2C-outlo and I2C-outHi are incorrect they should be I2C_outlo and I2C_outHi.
    When I was cleaning up the code for posting I did not notice this error. It was only when I compiled the code later that the error became apparent.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. isd4002 problems help required please
    By Agent36 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2012, 06:57
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  5. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33

Members who have read this thread : 1

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