USB Serial on PIC24FJ256GB106

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

USB Serial on PIC24FJ256GB106

Post by csouter »

I am attempting to use the USB Serial component on a board with a MicroChip PIC24FJ256GB106, and am experiencing problems. Most notably, it hangs the CPU when I attempt to call USB_Serial::Initialise. I have also noticed when I build the project, I am getting a warning (error?) "Options have been disabled due to restricted license". I do not know if this is part of the problem, or something unrelated. Can you possibly explain why the USB_Serial::Initialise function does not work?

Thank you.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello,

Please can you try adding the updates available here and letting me know how you get on.
viewtopic.php?f=63&t=18760

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Benj:

I had already applied those updates - they didn't help :(

Respectfully:
csouter

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello csouter,

The files have changed today. Have you tried the new files from today's update? I haven't changed the date on the update zip but the files inside have been changed.

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

I'm sorry, I misunderstood. I will try the new files and get back to you.

Thank you!
csouter

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Benj:

I tried the new files. Behaviour is the same as before. It locks up on the USB_Serial::Initialise call and won't go any further in te program.

Thank you for your support.
csouter

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by LeighM »

Is the USB connected to a host?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Please can you post your program to the forums so we can have a look.

The initialise function is designed to wait until the USB has been enumerated on the PC and the driver has been installed. If you look in your windows device manager with the micro powered on then do you get any unrecognised devices?

A signed version of the USB serial drive can be found here if you need to try and install it.
download/file.php?id=17771

Other things that could cause the enumeration to fail include the device not being run at a USB compatible speed. What is your clock source and speed on your circuit. This combined with your Flowcode project should be enough to see if you have things correct for the USB to work. If the speed is not right then you will probably get an unrecognised device error message popping up on the PC and in the device manager.

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Benj:

Still no luck - what should the processor speed be set to? I think I have it set to 20000000, or at least, that is what I tried to set it to. I have a stripped down program that demonstrates the failure; I'm going to try and upload it. However, there doesn't appear to be any device in windows on my host computer to correspond with the USB Serial interface :( I am also bothered about the compiler warning/error that says options have been disabled due to a restricted license. My license should have enabled me to have the USB comms module.
HD12_17 - USB.fcfx
(18.42 KiB) Downloaded 192 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello,

I'll have a look at your project file now and see if I can make any suggestions.

For USB to work you need a specific speed to drive the USB component, on this device it is 48MHz if you look at figure 8-1 on page 121 of the device datasheet.

It looks like the device has two registers PLLDIV and CPDIV which allow the 48MHz to be generated based on your user clock speed.

As I say if the speed was wrong you should get an unrecognised device error, do you get anything in Windows Device Manager when plugging in the device?
I am also bothered about the compiler warning/error that says options have been disabled due to a restricted license.
This is related to the compiler and not your Flowcode license. We use the compilers in free mode and that is fine for USB operations.

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Benj:

No, my PC doesn't recognize anything when I connect the two together. I did install the driver you provided, that didn't nake any difference.

Thank you for the quick support!
csouter

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello,

In your config settings try enabling the 96MHz PLL and also set the USB 96MHz PLL Prescale to match your current clock speed.

Also try enabling the Internal USB 3.3V Regulator.

Finally have you tried a 1 second flasher before the USB enable to ensure your device is running at the speed you think it is.
https://www.matrixtsl.com/wikiv7/index. ... ED_flasher

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Benj:

That information helps a lot, however (I hope I'm not sounding like a total idiot), I can't remember how to bring up the display for the configuration settings. Can you please remind me how to get that back on the screen again?

Thank you
csouter

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Never mind - I found it.

Thanks again for the support
csouter

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Ben:

I hate to be a pest. But do you have a sample project that uses the USB on a PIC24? We still can't get our system to initialize the USB port-it hangs up the system (permanent wait), with the system connected to a host. We have the new USB serial driver installed on the PC host, but the host PC just doesn't want to recognize the port either. We have nothing. I've tried going through the data sheet to verify that I have all of the options set properly, and can't find anything. I'm sorry, but I'm sort of pulling my hair out. If You have a project that works, I can use that as my baseline to get started.

Thank you very much for your time and understanding.

Respectfully:
scouter.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello,

Please can you post your current project and I'll take another look for you. If you have a schematic or basic description of your hardware then that would also help.

How did you get on with the 1 second flasher tests?

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Ben:

I have uploaded a simple test program that just attempted to initialize the USB serial component, and if it succeeds, it starts flashing an LED at 5HZ (similar to your 1 second flasher program. If I disable the icon for the USB_Initialise, the LED does flash, and I have scoped it at a very precise 5HZ flashing, so the CPU is running at the correct rate (as far as I can tell). I think if I can get this program to work, I can figure out the rest of what I need to handle sending the report string to the host PC.

Thank you very much for your effort.

Respectfully:
csouter.
Attachments
HD12_17 - USB.fcfx
Simple test program for USB Serial
(18.42 KiB) Downloaded 134 times

csouter
Posts: 21
Joined: Fri Jul 28, 2017 10:58 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by csouter »

Ben:

I was wondering if you had a chance to look at the project file I uploaded. Due to restrictions that I have here at work, I can't provided schematics or the actual project that I am working on. :( Sorry.

Thank you.
csouter

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USB Serial on PIC24FJ256GB106

Post by Benj »

Hello csouter,

Do you get anything happening in Windows device manager when you reset or insert the device. Ideally it should refresh itself when you insert or unplug a device.

I would try to keep playing with the configuration settings, maybe try the "Primary Oscillator + PLL" for Oscillator Select.

Maybe try disabling the internal/external switchover mode?

I can't see anything too bad.

Can you reduce the schematic so it's just the micro, the crystal and the USB socket? Without being able to see I'm basically guessing what the problem might be.

Just noticed in your program that the Send_32_Bit macro code is slightly wrong.

You are using a single 0xF mask for the value but this looks incorrect as this is only 4 bits. Try this instead.

(.Data_Value & 0xFF000000) >> 24
(.Data_Value & 0x00FF0000) >> 16
(.Data_Value & 0x0000FF00) >> 8
(.Data_Value & 0x000000FF)

Post Reply