• AVR Freaks

Hot!Harmony I2C overview

Author
GSQ
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2018/08/02 06:52:31
  • Location: 0
  • Status: offline
2018/08/29 11:40:37 (permalink)
0

Harmony I2C overview

Hello,
 
I am trying to interface a PIC32MX675F512 with MCP23017 GPIO expander through I2C_ID_1. I like how harmony sets up library to have most of the functions handled by interrupts. However I'm having a little bit of trouble working with the Harmony I2C library and was looking for some pointers. What is the best way to interact with the library? According to Harmony I2C Driver Library Help the I2C line first needs to be initialized, opened, status set to SYS_STATUS_READY and then data can be transmitted and received. Is this the case?
 
DRV_I2C0_Initialize
This seems to work fine but I can't tell from the code how long this takes. Can I call DRV_I2C_Open on the next line or do I need to wait for some flag to be set? Is this even the correct function to use? A lot of the forums suggest DRV_I2C0_MasterStart.
 
DRV_I2C_Open
What format does index need to be? I assumed that it was supposed to be I2C_ID_1 but that doesn't work. How important is intent? Do I need to close and open the instance each time I switch from reading to writing? Can I just OR read and write?
 
DRV_I2C_Status
When can this be used? Should it used before or after DRV_I2C_Open? What should object be? Again I assumed that it should be I2C_ID_1, but that throws errors.
 
DRV_I2C0_Transmit
In the example it gives size as size minus 1. Should this always be done? If the buffer is larger than 1 will it automatically transfer the next byte? Will DRV_I2C_Status say when the transmit is complete?
 
Are these functions the best way to interact with the library? Are there higher level functions that can do this better? Are all of these steps required? When I was looking through DRV_I2C0_Transmit it looked like the function would start to initialize the drive if it hadn't been already. I've been looking at the example code given (not very helpful honestly) and going over the forums (kind of helpful) and this seems like this is a problem that has been around for a while. Is there some document or tutorial that I am missing?
 
Harmony Configuration
Driver Implementation [STATIC]
Static Driver Type [BUFFER_MODEL_STATIC]
Interrupt Mode [X]
Include Force Write I2C Function (Master Mode Only - Ignore NACK from Slave) []
I2C Driver Instance 0 [X]
I2C Module ID [I2C_ID_1]
Operation Mode [DRV_I2C_MODE_MASTER]
I2C Interrupt Priority [INT_PRIORITY_LEVEL4]
I2C Interrupt Sub-priority [INT_SUBPRIORITY_LEVEL0]
Baud Rate Generator Clock [400000]
Slew Rate COntrol []
Power State [SYS_MODULE_POWER_RUN_FULL]
 
System Info
MPLAB X IDE v5.00
Harmony v2.06
Compiler: xc32 v2.10
#1

8 Replies Related Threads

    WalterH
    Starting Member
    • Total Posts : 56
    • Reward points : 0
    • Joined: 2007/02/25 07:06:21
    • Location: Austria
    • Status: offline
    Re: Harmony I2C overview 2018/09/03 10:41:47 (permalink)
    0
    Hi,
     
    harmony_help_volume_V_part_i.pdf page 1888 shows an example code for i2c. I use this code and found one issue, DRV_I2C_TransferStatusGet returns an error if called to fast, so I inserted a short delay before state APP_STATE_DATA_CHECK. This delay I implemented as separate state after APP_STATE_DATA_PUT
    and before APP_STATE_DATA_CHECK. 
     
    Hope this helps.
     

     


    #2
    GSQ
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2018/08/02 06:52:31
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2018/09/07 09:50:47 (permalink)
    0
    Yeah that is pretty close to what I am already doing. The main issue I am running into now is that I get errors whenever I use the DRV_I2C_Status function. I'm using the PLIB_I2C_BusIsIdle(I2C_ID_1) function instead. 
     
    I have to admit it is frustrating that Microchip would make the interface so hard to use. Most other platforms I've worked with accomplish this with a couple of lines of code. Up to date examples go a long way as well. I'll try to have a longer follow up post about this later when I am certain I have everything up and running.
    #3
    danchoi955
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2010/08/30 07:17:04
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2019/02/08 16:34:41 (permalink)
    0
    Just came across this thread...just started using Harmony, and I can't say it's more helpful.  Almost like trying to learn to walk again.  I am using the PIC32MZ and trying to use I2C to control a couple of MCP23017's.  I got the pins setup and the I2C Driver included, but I am not sure where to go from here.  Does anyone have some working sample code that they can share, at least to get me started.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17847
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2019/02/08 19:08:02 (permalink)
    0
    Harmony Comes with examples:
    C:\microchip\harmony\v2_05_01\apps\driver\i2c\i2c_rtcc
    C:\microchip\harmony\v2_05_01\apps\examples\peripheral\i2c\i2c_interrupt
     
    in V1.XX The I2C driver was a wreck. I do not know if they fixed it in V2.XX
    #5
    Paul PortSol
    Super Member
    • Total Posts : 493
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Harmony I2C overview 2019/02/11 05:47:46 (permalink)
    0
    PIC32MZ - Ensure you select the "Bitbang" option for I2C. (Other threads talk about this).
    #6
    D4ILYD0SE
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2019/02/12 15:34:09
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2019/08/27 13:04:50 (permalink)
    0
    Here we are in the Harmony 2.06 world and I can't get the Application Code Generated by the Harmony Configurator to do anything.  To top it off, it doesn't allow one to debug.  The debugger doesn't/can't compile.  Any thoughts on this?
    #7
    henkebenke
    New Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2008/09/27 23:55:51
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2019/10/07 18:44:56 (permalink)
    0
    I just started to look at the Harmony I2C module, and the abstraction is horrifying. 
    I think I'm going to use Harmony just to set up the basics.
     
    The I2C as master can easily be emulated. It's crude, but if the communication is done in the main loop, it's good enough to interface displays, etc. Just google "emulating I2C master C" and you will find example code.
    It's perhaps some 100 lines of code.
     
    To use slave emulation is not that simple, it needs interrupts to be set up and a proper state machine. But there are examples out there. Not too complex.
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 17847
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Harmony I2C overview 2019/10/07 19:12:23 (permalink)
    0
    You are a few months late (August 2018 / Feb 2019 / August 2019) The HW is fine and The Harmony PLIB give you access functions.  But you could write to the Register directly.  Bit Banging is Not Needed, unless you have a Chip with Errata, like the PIC32MZ  ECH.
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5