Programming PIC18F24K22 for I2C


+ Reply to Thread
Results 1 to 4 of 4

Thread: Programming PIC18F24K22 for I2C1438 days old

  1. #1
    jom
    Guest jom's Avatar

    0 Not allowed!

    Default Programming PIC18F24K22 for I2C

    Hello all

    I'm back yet again to programming for a PIC on a project. Every time I start up again I always end up back here when I run into a wall. The problem is that I simply don't work with PICs in a sustained manner to remember everything. I'll forget what I learned when I don't get back to programming for 6 months or a year. Frustrating but what can I do?

    Anyways, this time I need to program a PIC to be an I2C "slave". I have to bring in I2C data and then spit out the data in SPI format (as the "master") to several peripheral devices. Some quick questions:

    1) Is it necessary to use the built in Hbusout (etc) commands in PDS or can you program the SSP module yourself? If so, does anyone have a code example? If you were to program the SSP module itself can it be done like with SPI such that you don't have to do a direct bit-bang and let the module itself do the functions?

    2) I'm curious...are the Hbus commands what they call a "bit banging" method? I looked at the assembly and that seems to me what is going on.

    A dumb Compiler question...best asked with a specific example: What the best way to access the low half of a register byte without disturbing the top bits? Let's say I set up a symbol to describe Bit 5 of SSP2CON1 as:


    Code:
      Symbol SSP1EN = SSP1CON1.5                       ' SSP1 Enable bit
    ....
      SSP1EN = 1                                                 ' Set Enable bit
    
    Then later I need to set the bottom four bits as:
    
    
        SSP1CON1 = 10                ' SSP1M Bits (3:0) set to I2C Slave Mode, 7-bit address
    I assume here the last command doesn't overwrite the top bits of SSP2 with zeros....is that true? Is there a cleaner way to do this? That's a dumb little issue I've had...I usually just dump the idea of doing the Symbol set up and just write to the whole register at once (SSP1CON1 = %XXXXXXXX) but I thought I'd ask this time.

    Thanks again all and have a good holidays.

    jom

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster shantanu@india's Avatar
    Join Date
    Feb 2007
    Posts
    1,701
    Thumbs Up
    Received: 7
    Given: 21
    Total Downloaded
    827.23 MB

    0 Not allowed!

    Default Re: Programming PIC18F24K22 for I2C

    Hi,
    I am also currently doing a project with 18F24K22 where a RTC(I2C) has to be read.
    The PIC is in master mode , but still you might have a look at my code.....http://www.protonbasic.co.uk/showthr...ts-with-HBusin
    Hbusin/Hbusout should make life easier for you since they usually work like a dream...
    To set a bit you have to bitwise OR with a byte with that particular bit set to 1 & all the other bits 0 , and to reset a bit you have to bitwise AND with a byte with that particular bit set to 0 & all the other bits set to 1.
    Shantanu

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    jom
    Guest jom's Avatar

    0 Not allowed!

    Default Re: Programming PIC18F24K22 for I2C

    OK, since you Hbusin etc can you tell me what the difference is between those and Busin and Busout etc? The manual says they are also for I2C so which should you use?

    In fact, the manual also states that these commands (both the Hbus and Bus) were "somewhat lacking" and implied a "new structure". What is that referring to? Were the commands re-written in the compiler at some point? The manual isn't clear.

    Thanks

    jom
    Last edited by jom; 14th December 2015 at 20:07.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Prolific Poster shantanu@india's Avatar
    Join Date
    Feb 2007
    Posts
    1,701
    Thumbs Up
    Received: 7
    Given: 21
    Total Downloaded
    827.23 MB

    0 Not allowed!

    Default Re: Programming PIC18F24K22 for I2C

    Hbusin & Hbusout commands use the hardware MSSP module whereas Busin & Busout commands generate the I2C waveform through software.
    Since you are using a PIC with a MSSP module , there is no reason to use Busin & Busout.
    Shantanu

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Replies: 10
      Last Post: 10th January 2016, 15:50
    2. [SOLVED !] I2C programming problems
      By adamsj3 in forum Proton Plus Compiler v3
      Replies: 2
      Last Post: 11th February 2013, 10:34
    3. Pic18F25K22 or Pic18F24K22 QFN
      By Tim in forum The Lounge
      Replies: 6
      Last Post: 11th October 2010, 07:29
    4. Self-Programming
      By Tasos Stratis in forum Proton Plus Compiler v3
      Replies: 17
      Last Post: 22nd October 2006, 23:54
    5. getting started in programming
      By C_Moore in forum The Lounge
      Replies: 30
      Last Post: 25th August 2005, 20:03

    Members who have read this thread since 4th November 2019, 23:11 : 0

    Actions :  (Set Date)  (Clear Date)

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

    Tags for this Thread

    Posting Permissions

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