![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
FFT
Joined: 07 Jul 2010 Posts: 92
|
Request: USB HID Test code for 18LF14K50 12MHz [Solved] |
Posted: Mon Oct 18, 2021 1:58 pm |
|
|
Hello,
I'm having trouble getting running the full speed or low speed USB HID.
Currently my code has no effect when device is plugged into USB.
I generated the USB code using CCS Wizard.
(PIC and the PCB work properly, it can read ADC and set LEDs successfully)
I use HID Terminal GUI for testing but I don't see my device there.
I need a working USB HID test code for 18LF14K50, can somebody help me?
* 12MHz external crystal connected to RA4(2), RA5(3)
* VCC is 3.3V
* USB power detect pin is PIN_C0(16)
* VUSB(17) pin is connected to 3.3V directly and a 1uF next to the pin
* D+(19) and D-(18) pins are connected to USB socket over 33R resistors
* MCLR ON
* All other pins are inputs
I cannot understand what is wrong with it.
I'm sure it will be useful for other people as well.
Thanks
Last edited by FFT on Thu Dec 16, 2021 11:01 am; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon Oct 18, 2021 2:02 pm |
|
|
It may not be a PIC problem, what are you connected to ? If a Windows based PC, run USBView or similar program to CONFIRM the USB port the PIC is connected to is configured for high speed mode... |
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Mon Oct 18, 2021 2:32 pm |
|
|
temtronic wrote: | It may not be a PIC problem ., what are you connected to ? If a Windows based PC, run USBView or similar program to CONFIRM the USB port the PIC is connected to is configured for high speed mode... |
I did it, all seems good. I can run an STM32 USB HID device on the same port. |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Mon Oct 18, 2021 3:10 pm |
|
|
Quote: | * VBUS(17) pin is connected to 3.3V directly and a 1uF next to the pin |
Is this connection correct? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Oct 19, 2021 12:35 am |
|
|
The connection is OK, but the capacitor is wrong. It requires a 0.22 to 0.47uF ceramic capacitor. If the 1uF is electrolytic, it won't have a low enough ESR.
To the original poster, post your setup lines. Clock setting etc..
With a 12MHz crystal, you need something like:
Code: |
#include <18LF14K50.h>
#device ADC=10
#FUSES NOWDT
#use delay(clock=48MHz,crystal=12MHz,USB_FULL)
#define USB_CABLE_IS_ATTACHED() input(PIN_C0)
#define USB_CONFIG_BUS_POWER 500
#include "ex_usb_common.h"
#define USB_CONFIG_HID_TX_SIZE 2
#define USB_CONFIG_HID_RX_SIZE 2
//these need to be set if you intend to use the hiddemo code
#include "pic18_usb.h" //hardware layer for PIC18
#include "usb_desc_hid.h" //now the HID descriptor
#include "usb.c" //and the basic handlers
//Then your code. Remember this must call usb_init_cs or the
//unit will not be seen.
|
|
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Tue Oct 19, 2021 11:36 am |
|
|
@Ttelmah, I just tested the code snippet you provided but nothing happens. It does not enumerate at all.
The VBUS pin is connected to 3.3V and I have few 10uF capacitors on the 3.3V line. So the 1uF is not alone there. Do you think the 1uF is the problem?
Could you supply a working test code if you have the PIC?
BTW I get those warnings:
Quote: | >>> Warning 216 "main.c" Line 177(1,2): Interrupts disabled during call to prevent re-entrancy: (@READ_PROGRAM_MEMORY)
>>> Warning 216 "main.c" Line 177(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_token_reset)
>>> Warning 216 "main.c" Line 177(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_tbe)
>>> Warning 216 "main.c" Line 177(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_flush_in)
|
|
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Tue Oct 19, 2021 6:27 pm |
|
|
The 18LF14K50 microcontroller not use the standard scheme for the Vusb pin, connected to ground in series with the capacitor(470n)? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Oct 19, 2021 10:50 pm |
|
|
Quote: |
@Ttelmah, I just tested the code snippet you provided but nothing happens. It does not enumerate at all.
|
Of course it won't. That is a header, not the code.
I use the chip for CDC, not HID, and it runs fine. Different crystal, and
I followed the Microchip wiring for all the pins. Including decoupling
right by the chip.
Have you proved the chip is actually running, and running at the expected
clock rate?. Needs to be done before anything else. |
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Wed Oct 20, 2021 9:26 am |
|
|
Ttelmah wrote: | Of course it won't. That is a header, not the code. |
I use a main loop with usb send packets, so I didn't use your header only.
Ttelmah wrote: | I use the chip for CDC, not HID, and it runs fine. |
Can you share the code?
Topic is created for a USB test code. It can be CDC, no problem.
Ttelmah wrote: | Have you proved the chip is actually running, and running at the expected clock rate? |
The chip is running, I tested ADC, I2C and GPIO (Leds, Buttons).
How to test the clock rate?
VBUS:
VBUS pin is connected to VCC which is 3.3V
If it was not LF chip, it would have it's own regulator, but LF chip has no regulator. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Oct 20, 2021 9:32 am |
|
|
Testing speed is easy. You just run a loop set a pin high delay for
1000mSec, set it low, delay again, and loop. Attach an LED to the pin. if it
does flash 5 times in 10 seconds, the the clock rate is right. If not
there is a clock problem. USB will never work if the clock is wrong.
I asked right at the beginning for you to post the header stuff you are
using. I repeat this. |
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Wed Oct 20, 2021 11:13 am |
|
|
I tested the clock rate using LEDs, it looks exact.
Here is my test code:
Code: | #include <18LF14K50.h>
#device ADC=10
#fuses WDT
#fuses WDT128
#fuses NOIESO
#fuses NOFCMEN
#fuses PCLKEN
#fuses NOPUT
#fuses NOBROWNOUT
#fuses MCLR
#fuses NOHFOFST
#fuses NOLVP
#fuses NOXINST
// configure 12MHz clock for USB operation and 48Mhz CPU operation
#fuses HS
#fuses PLLEN //enable pll, we can now use CPUDIVx fuses
#fuses CPUDIV1 //CPU clock set to 48MHz
//#fuses USBDIV2 //when using low speed USB, need to divide 12MHz by 2. this fuse has no effect when using full speed.
#use delay(clock=48MHz,crystal=12MHz,USB_FULL,restart_wdt)
#use FIXED_IO( C_outputs=PIN_C4 )
//#define USB_ISR_POLLING // Comment to use interrupt
#define USB_CABLE_IS_ATTACHED() input(PIN_C0)
#define USB_CONFIG_BUS_POWER 100
//#define USB_USE_FULL_SPEED 1
//#define USB_MAX_EP0_PACKET_LENGTH 64 // 8 bytes buffer
#define USB_CONFIG_HID_TX_SIZE 8
#define USB_CONFIG_HID_RX_SIZE 8
#define USB_STRINGS_OVERWRITTEN
//!char USB_STRING_DESC_OFFSET[]={0,4,28};
char const USB_STRING_DESC[]={
//string 0 - language
4, //length of string index
0x03, //descriptor type (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1 - manufacturer
4, //length of string index
0x03, //descriptor type (STRING)
'E',0,
//string 2 - product
4, //length of string index
0x03, //descriptor type (STRING)
'S',0
};
#include <pic18_usb.h> // HID
#include <usb_desc_hid.h>
#include <usb.c>
bool Tick = FALSE;
#INT_TIMER0
void TIMER0_isr(void)
{
Tick = TRUE;
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); //87,4 ms overflow
setup_wdt(WDT_128MS);
usb_init_cs();
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
for(;;)
{
restart_wdt();
usb_task();
if(Tick == TRUE)
{
if(usb_enumerated())
{
char u[USB_CONFIG_HID_TX_SIZE];
strcpy(u, "test");
usb_put_packet(USB_HID_ENDPOINT, u, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);
}
Tick = FALSE;
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Thu Oct 21, 2021 1:04 pm |
|
|
Any help? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 21, 2021 2:16 pm |
|
|
You didn't copy Ttelmah's fuse setup. There are many differences
between his compiled fuses and yours:
Your fuses:
Code: | Configuration Fuses:
Word 1: 3220 CPUDIV1 USBDIV2 HS PLLEN PCLKEN NOFCMEN NOIESO
Word 2: 0F19 NOPUT NOBROWNOUT BORV19 WDT WDT128
Word 3: 8000 NOHFOFST MCLR
Word 4: 0089 STVREN NOLVP BBSIZ2K NOXINST NODEBUG
Word 5: C003 NOPROTECT NOCPB NOCPD
Word 6: E003 NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 4003 NOEBTR NOEBTRB
|
Ttelmah's fuses:
Code: | Configuration Fuses:
Word 1: F220 CPUDIV1 USBDIV2 HS PLLEN PCLKEN FCMEN IESO
Word 2: 1E1E PUT BROWNOUT BORV19 NOWDT WDT32768
Word 3: 8800 HFOFST MCLR
Word 4: 0089 STVREN NOLVP BBSIZ2K NOXINST NODEBUG
Word 5: C003 NOPROTECT NOCPB NOCPD
Word 6: E003 NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 4003 NOEBTR NOEBTRB
|
Your #fuses code:
Code: | #include <18LF14K50.h>
#device ADC=10
#fuses WDT
#fuses WDT128
#fuses NOIESO
#fuses NOFCMEN
#fuses PCLKEN
#fuses NOPUT
#fuses NOBROWNOUT
#fuses MCLR
#fuses NOHFOFST
#fuses NOLVP
#fuses NOXINST
// configure 12MHz clock for USB operation and 48Mhz CPU operation
#fuses HS
#fuses PLLEN //enable pll, we can now use CPUDIVx fuses
#fuses CPUDIV1 //CPU clock set to 48MHz
//#fuses USBDIV2 //when using low speed USB, need to divide 12MHz by 2. this fuse has no effect when using full speed.
#use delay(clock=48MHz,crystal=12MHz,USB_FULL,restart_wdt) |
Ttelmah's #fuses code:
Code: |
#include <18LF14K50.h>
#device ADC=10
#FUSES NOWDT
#use delay(clock=48MHz,crystal=12MHz,USB_FULL)
|
|
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Thu Oct 21, 2021 2:50 pm |
|
|
PCM programmer wrote: | You didn't copy Ttelmah's fuse setup. |
İf you check out this line below, you will see that the other fuses are added.
#include "ex_usb_common.h"
I also tested without ex_usb_common.h with the header and fuses you just mentioned but nothing happens.
Can somebody give me a working test code for USB as I requested on my first message? I have created the topic for just a test code.
I will find the issue if I get a working test code. It may be a HW issue.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Sat Oct 23, 2021 4:24 am |
|
|
Nobody has a test code? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|