• AVR Freaks

Hot!PIC32MK + USB = how?

Author
VyPu
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2019/07/08 14:06:43
  • Location: 0
  • Status: offline
2019/07/11 15:12:19 (permalink)
0

PIC32MK + USB = how?

Hello,
 
I use PIC32MK1024MCF064 microcontroller in my project. It has a quadrature encoder interface which together with fast overall performance are the main reasons why I selected it. 
 
Unfortunatelly, I cannot figure a way how to connect this controller to the computer using the usb. I cannot find any code examples which I could check for MCF series too. For setting up the device I am using harmony v2.06, because the new one (v3) doesn't support usb on this device yet. I create a new project, configure the usb and clock settings using harmony and then after programming the computer doesn't react to the connection anyhow.
 
My first question is - does anyone have seen any code examples illustrating the usb communication with this device?
 
Secondly, I have a feeling that there might be some problems with the clock settings. I am using 24MHz crystal as the primary oscillator and the source for System and USB PLL. For debugging I output the clock signal to REFCLK4. According to the clock settings (see attachment) I should see 48Mhz at the output, but I get only 24 Mhz. If I increase usb frequency to 96MHz, the output is still 24Mhz. Any ideas why?
 
Concerning the electronics part, I am using USB-C for connection. I have two 5.1k pulldown resistors on CC1 and CC2 lines. The D+, D- and Vbus lines are connected directly to the microcontroller. 
 
 

Attached Image(s)

#1

11 Replies Related Threads

    MisterHemi
    Senior Member
    • Total Posts : 178
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/16 12:30:51 (permalink)
    0
    I've never used the PIC32MK but perhaps it's similar to the PIC32MZ and maybe some code could be ported.
    Take a look at this thread:
    https://www.microchip.com/forums/m1083508.aspx

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #2
    TS9
    Super Member
    • Total Posts : 799
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/16 21:04:58 (permalink)
    0
    I think ... You should go as below:
    For USB Demo..Go to below path
    C:\microchip\harmony\v2_XX\apps\usb
    1)
    Open Desired Demo MPLAB X ..
    2)
    Go to properties
    3)
    Change Processor
    4)
    Check and Highlight options in MHC.
    5)
    Modify that doesn't exist in new choosen Processor
    6)
    Change suitable pins accordingly.
    7)
    Click Generate
    8)
    Build and Run on Hardware.

    It should work..

    Try this and update here.

    --
    TS9
    post edited by TS9 - 2019/07/16 23:22:51
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 18030
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32MK + USB = how? 2019/07/16 22:12:00 (permalink)
    0
    What kind of USB are you trying to use?
    #4
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/17 01:43:37 (permalink)
    0
    Thanks, I will try all your advices soon. I would like to try HID communication first, as it looks the most simple one.
     
    Does anyone know if outputing usb PLL to REFCLK4 should really give 48 Mhz? I was expecting 48 MHz, but instead I only get 24 Mhz (the crystal frequency). The frequency dividers are working, I can divide the 24MHz, but can't get any higher frequencies. If I really should get 48 MHz, then I guess I should start debugging the clock settings.
    #5
    JPortici
    Super Member
    • Total Posts : 833
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/17 04:57:35 (permalink)
    0
    FYI, harmony 3 has added support for USB in the 32MK in yesterday's update. I hope to have time to test it tonight, as i've been waiting for this for a long time
     
    (harmony 2.06 simply cannot handle the 32MK: No support for the dual usb, the host library is severly bugged. device seemed to be working, at times..)
    #6
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/17 12:17:16 (permalink)
    0
    JPortici, thanks. I updated the Harmony, but either I did something wrong, or the new harmony still doesn't support USB with PIC32MK. I cannot add usb library to my project when using this device.
     
    UPDATE: Actually MPLAB for some reason downloaded the older version again. I updated usb library to the newest one manually and now I can add it to the project! I am very curious if it will work, I will post my progress after I try it.
    post edited by VyPu - 2019/07/17 12:33:43
    #7
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/25 05:50:26 (permalink)
    0
    So, I was playing quite a a bit with the updated harmony, but didn't manage to start usb. 
     
    I tried to port existing examples for other microcontrollers, as well as the ones proposed here, but didn't manage to do it. The controllers are quite different and it is very easy to get lost. 
     
    I also tried to follow this guide: https://github.com/Microchip-MPLAB-Harmony/usb/wiki/Create-your-first-usb-device-cdc-single-application The only thing which was different is that I didn't use GPIO pin for UAB_VBUS_SENSE, not sure if this is important. Now 5V from USB are connected to the dedicated VBUS pin. I was expecting windows device manager to sense some changes, but nothing happened no matter what I tried.
     
    By the way, with the newest version of Harmony I can now output 48 Mhz UPLL clock to an external pin, I couldn't achieve this with older version.
     
    Any ideas? 
    #8
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/30 00:01:01 (permalink)
    0
    Small question - what are the minimum requirements which have to be fulfilled in order to detect any activity on USB either from PC side or from microcontroller side? For example, is there a simple interrupt which could be enabled manually and which could tell me, that the microcontroller detected connection? 
    #9
    JPortici
    Super Member
    • Total Posts : 833
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/30 00:17:40 (permalink)
    0
    IIRC if you follow the state machine model used in harmony there should be a "device attached" and a "device detached" state so you can detect the event in your main loop
     
    were you able to make it work? i still haven't found time to try. pity
    #10
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/07/30 07:01:15 (permalink)
    0
    Thanks, I will give it a try soon. The newer version of Harmony seems to be significantly improved in case of PIC32MK, but I am still struggling to start USB. Today I also got the DM320106 developement board (slightly different PIC), so will try it too.
    #11
    VyPu
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/07/08 14:06:43
    • Location: 0
    • Status: offline
    Re: PIC32MK + USB = how? 2019/08/01 13:56:15 (permalink)
    0
    Finally I managed to make my pcb work. The main problem was, that I naively expected some USB activity after simply generating the code with harmony. After playing with the demo board and analysing the examples I realized, that I also need to write some code. I took most of the code from "cdc com port single" demo and now everything seems to be working. I guess it is the same story with HID. This is my first Harmony and PIC32 project, so still I have a lot to learn. Thank you all for your help!
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5