• AVR Freaks

Hot!I2C Bit Bash on PIC32MZ with Harmony 2.06

Author
laffelt
Super Member
  • Total Posts : 135
  • Reward points : 0
  • Joined: 2008/05/08 18:05:53
  • Location: 0
  • Status: offline
2019/08/20 07:12:36 (permalink)
0

I2C Bit Bash on PIC32MZ with Harmony 2.06

I am working on a project with the PIC32MZ2048EFG064 with Harmony 2.06 and XC32 2.10.
In a previous project with a PIC32MZ and Harmony 1.09 I used my own I2C code with Harmony configuring the I2C port and I saw the issues reported in the errata and created several workarounds (transaction timeouts, bus resets) and was able to get reasonable reliability in production. 
I want to use the I2C bit bash option in Harmony to maximize the reliability of this peripheral but I cannot find any examples in the Harmony examples or elsewhere. I do not want to make a complex state machine, I have a lot of slack time in my application so I want to initiate the transaction and call the appropriate task function to complete it.
Can anyone share an example or provide guidelines for using the bit bash in Harmony? I have not used the upper level harmony functions for I2C so any help would be greatly appreciated!
 
Larry Affelt
#1

6 Replies Related Threads

    nigelwright7557
    Super Member
    • Total Posts : 282
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: online
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/08/20 07:29:30 (permalink)
    0
    I just read the datasheet for the I2C chip I was using and wrote the clock data/code for it.
    Its not hard to do basic read and writes. Keep it simple.
    There shouldn't be any issues with I2C so long as you dont do something silly like clock it too fast.
    I found it very reliable.
     
    post edited by nigelwright7557 - 2019/08/20 07:30:57
    #2
    LostInSpace
    Super Member
    • Total Posts : 263
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/08/20 21:35:13 (permalink)
    0
    I also bit bang (bash?) my I2C on the PIC32. Microchip has an example driver, but it uses a timer and a state machine, like you, not what I wanted. So I just bang and wait, etc. I was able to tune the code by hand for 1000 kHz operation and then I have a Init routine so I can adjust the clock up and down to 100, 400 and 1000 kHz operation at run-time.
     
    If you don't know where to start - then IMHO, Melexis has roughed out a wonderfully simple and concise driver for use with one of its sensors, really if I had to do it again, I would use this as a guide,
    https://github.com/melexis/mlx90640-library/blob/master/functions/MLX90640_SWI2C_Driver.cpp
    I didn't know about that when I started, so I used the Philips (now NXP) application notes  to develop my driver + I looked at some GNU Arduino drivers to see how others have done it (API ideas, etc). I think the Melexis code is better however.
     
    NXP Reference,
    https://www.nxp.com/docs/en/user-guide/UM10204.pdf
    https://www.nxp.com/docs/en/application-note/AN10216.pdf
     
    Here is a step by step guide from Microchip that describes the interface in some detail (I liked the NXP info better, but to each his own, this is a different way of describing the I2C operation.
    http://ww1.microchip.com/downloads/en/AppNotes/01488A.pdf
     
    Hope this helps
     
    #3
    laffelt
    Super Member
    • Total Posts : 135
    • Reward points : 0
    • Joined: 2008/05/08 18:05:53
    • Location: 0
    • Status: offline
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/08/22 06:30:46 (permalink)
    0
    Thanks to all ...
     
    I write my own bit bang(bash) driver based on the Microchip app note and the NXP docs too.
    My original code used the I2c port as configured by Harmony and looked for the appropriate INT flags for task completion with INT's disabled and used the bit controls to execute a start or stop. This was all in a state machine controlled i2c_poll() function which I simply called until completion.
     
    I replaced those functions with true bit bang code and with some simplification of my code (ie: not waiting for tasks to finish) this is working perfectly. I have an EEPROM and RTCC on the bus.
     
    Some speed tweaking and I am finally done fighting with the the Microchip PIC32MZ I2C hardware!
     
    Larry
    post edited by laffelt - 2019/08/22 06:33:25
    #4
    LostInSpace
    Super Member
    • Total Posts : 263
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/08/22 14:10:08 (permalink)
    0
    It's true what Larry says about being 'free' - I have some very old code that was bit bang SPI to several devices. I recently ported the code to a new chip and had the whole thing done in a day. While it took most of a week to get a another new application to run properly on a chip that had built in SPI. Now truthfully, I can't bit bang at 40 or 50 MHz like I can with the new SPI hardware, but Bit Banging is easy to port to anything and easy to understand. Plus you learn a lot about your target chip as you are writing the driver.
     
    :-)
    #5
    steverap
    Super Member
    • Total Posts : 157
    • Reward points : 0
    • Joined: 2003/11/07 12:38:54
    • Location: San Jose, CA, USA
    • Status: offline
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/08/22 15:26:19 (permalink)
    0
    The I2C errata issues are fixed in silicon Rev B2. I'm using a PIC32MZ2048EFM144-I/PHN23 with the Harmony 2.06 I2C driver at 400 kHz without any issues. However, to get your hands on just a few chips, you have to request samples from Microchip. Otherwise, you have to buy them in lots of 90 chips.
     
    Steve
    #6
    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: I2C Bit Bash on PIC32MZ with Harmony 2.06 2019/09/03 01:46:27 (permalink)
    0
    Easy: In MHC simply click on the "bit bang" checkbox under the I2C peripheral, works fine for PIC32MZ, I've been using in Hv206 for ages.
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5