USB Serial on PIC24FJ256GB106
Moderator: Benj
USB Serial on PIC24FJ256GB106
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.
Thank you.
- 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
Hello,
Please can you try adding the updates available here and letting me know how you get on.
viewtopic.php?f=63&t=18760
Please can you try adding the updates available here and letting me know how you get on.
viewtopic.php?f=63&t=18760
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: USB Serial on PIC24FJ256GB106
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: USB Serial on PIC24FJ256GB106
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.
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

- 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
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'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?
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.I am also bothered about the compiler warning/error that says options have been disabled due to a restricted license.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: USB Serial on PIC24FJ256GB106
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
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
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: USB Serial on PIC24FJ256GB106
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
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
Re: USB Serial on PIC24FJ256GB106
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.
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.
- 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
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: USB Serial on PIC24FJ256GB106
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.
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 188 times
Re: USB Serial on PIC24FJ256GB106
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
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.

Thank you.
csouter
- 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
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)
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)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel