Still new to PicBasic - i2c questions


Closed Thread
Results 1 to 5 of 5
  1. #1
    cometboy's Avatar
    cometboy Guest

    Default Still new to PicBasic - i2c questions

    Thanks for getting me started on the LED blinking, finding out about the POKE command for setting the correct clock rate was a big thing for me.

    I'm using the i2cout command at this time and have a few questions.

    1) the command seems to work for some PICs but not others. I get a compiler error - undefined symbol PortA for a 12F629, but not for a 16F819.

    Is this a correct diagnosis?

    2) What kind of preliminary housekeeping commands would I need to set up the 16F819 for i2c operation. I'm sure that I have to set the clock rate (4MHz) and the PortA,0 and PortA,1 as outputs, but anything else?

    3) The command i2cout has me a little confused. The first variable is the control code, with the leading bite determining the address as word or byte. The next variable contains the i2c device address.

    I am going to be talking to a PCA9633 PWM LED driver. Theis device has no control code, only a slave address. Once the slave answers the address byte, you start feeding it data to set the LEDs.

    I have sucessfully run this device using another PIC device, the PicAxe, from England. The data sequence was ADDRESS,DATA,DATA... with no control code.

    I'm sure a lot of this is pretty inchoherent, but I'm just learning how to ask questions in PBC. I'm also working on this in parallel, so might find the answers myself. But your last answer really helped, so here I am.

    Thanks.

    Alan

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Let me take number 1.

    Quote Originally Posted by cometboy
    ...

    1) ...I get a compiler error - undefined symbol PortA for a 12F629, but not for a 16F819.

    Is this a correct diagnosis?...

    Alan

    Alan,

    Check the datasheet of 12F629.
    You will see that the PORTA does not exist.
    You will see GPIO.

    PORTA is valid for 16F819. TRISA is also.
    You get these as GPIO and TRISIO for 12F629.



    ------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    I'll take #3:

    The example in the PicBasic manual assumes an I2C EEPROM. So, it uses the word "control" for the device address, and "address" is the memory address inside the EEPROM. So, in your case, I would try it using the following construct:

    I2COUT address, data1, (data2, ....)

    HTH
    Steve

  4. #4
    cometboy's Avatar
    cometboy Guest


    Did you find this post helpful? Yes | No

    Default Still no i2c action

    I'm still getting no joy from the i2c command. I'm using a PIC16F819 chip with the following program.

    Using a scope on PortA,0 and 1, I see no modulation on either line. The two lines stay high from the 10Kohm pullup resistors on the slave device.

    poke $8F,%01100000 'set oscillator to 4MHz - OSCCON
    poke $03,%00110000 'set to Bank 1 - STATUS
    poke $85,%00000000 'set PortA all outputs - TRISA
    symbol addr = %00101010
    symbol blah = $80
    main:
    i2cout addr,blah,($00,%0000100,255,0,0,%10000000,$FF,$00, %10101010)
    pause 100
    goto main

    Any clues? Thanks for the previous comments.

    Alan

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


    Did you find this post helpful? Yes | No

    Default

    first observation, you forgot to disable the analog stuff on those Pins.

    POKE $9F,7

    And i think PBC handle the bank switch for you... i think.
    Last edited by mister_e; - 13th November 2006 at 18:30.
    Steve

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

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. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  4. i2c PBP questions
    By TimV in forum General
    Replies: 14
    Last Post: - 5th February 2007, 17:58
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

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