View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Wed Feb 12, 2025 6:22 am |
|
|
Ttelmah wrote: |
The VBUS signal uses a charge pump to
generate this when the chip is being used for USB OTG. Now you
can use this to detect the power good as you show, but you must have
a pull down resistor on this pin, otherwise the signal will be seen high
even when there is no connection, and you need to add the code to
test this. Pull down should be something like 47K to 100KR. Microchip
also recommend the input resistor is a lot larger to prevent the possibility
of damage to the chip 2K2 or 4K7.
Then with that attached, you need the following line in front of
loading the usb driver:
Code: |
#bit U1OTGSTAT_SESVD=getenv("BIT:SESVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD)
//cable attached for DsPIC
#include <usb_cdc.h> //Usb
|
This then uses the SESVD bit from the USB comparator to give
'cable_is_attached' detection.
Now, the USB cdc driver already has a 256 byte receive buffer, so
get rid of your added buffer code. |
Is this needed, bacause I can use also function "usb_enumerated()"? |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Thu Feb 13, 2025 3:20 am |
|
|
Yes, _required_ by the USB spec.
A USB connection can be live, but not enumerated, and enumeration does
not drop immediately on a disconnect. |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Thu Feb 13, 2025 4:26 am |
|
|
Ok,
What I have to do when see " USB_CABLE_IS_ATTACHED()" or not?
How to use this in main loop? |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Thu Feb 13, 2025 6:41 am |
|
|
The driver itself uses USB_CABLE_IS_ATTACHED, internally. You do not
have to do anything with it. |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Fri Feb 14, 2025 3:36 am |
|
|
Hi,
The "USB_CABLE_IS_ATTACHED()" add doesn't solved the problem. I have no experiance with MPLAB, XC, .. to try load some usbs cdc example to check if it work or not. When test with widows 10 some time I'm getting this error when usb device 'freeze'.
https://easyupload.io/0is6gv
And start to work when switch power off and on.. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9425 Location: Greensville,Ontario
|
|
Posted: Fri Feb 14, 2025 6:10 am |
|
|
OK, I don't use that PIC and USB but...
USE USBView and see if the port you're connecting to is 'power limited'.
If the PIC is being powered from USB port, it may be a PC side USB 'setup' issue.
On another forum,guy was having problems as USB 3 wasn't setup the way USB 2 port was.
This may not be your problem, but something to consider or at least eliminate.
Does a mouse or other device work on that port ?
It's not ALWAYS the PICs fault !!! |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Fri Feb 14, 2025 8:48 am |
|
|
Hi,
Same 4 usb ports with same example on PIC18F26J50 works with no problem!
Best Regards, |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9425 Location: Greensville,Ontario
|
|
Posted: Fri Feb 14, 2025 9:52 am |
|
|
hmm, that kinda eliminates the PC side !!!! |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Fri Feb 14, 2025 12:57 pm |
|
|
Key to understand is these are completely different chips with different
requirements.
On the PIC18, you are running with a 5v supply to power the USB
drivers. On the 16bit PIC you have a 3.3v device which requires the
VUSB3v3 line to power the transceivers. This can connect to Vdd. but
when USB is used, it must have it's own decoupling.
The cable_is_attached won't fix your problem. The point tis that this
is a USB requirement, so needed to be fixed. |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Wed Feb 19, 2025 3:52 pm |
|
|
Hi,
Sorry for delayed resp.
Mr. 'Tt' I have made all yours hardware edit suggestion and nothing change. Problem still present.
Best Regards, |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19730
|
|
Posted: Thu Feb 20, 2025 2:25 am |
|
|
OK.
I really do suspect you have another issue that is causing this. Problem
is working out what it is.
I've generated a cut down version of your test code, with a couple of
small changes, for basic testing:
Code: |
#include <33EP512MU810.h>
#device ICSP=1
//#device PASS_STRINGS=IN_RAM
#build (STACK=0x200)
#use delay(clock=32MHz,crystal=8MHz,USB_FULL,AUX:clock=48MHz)
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES BROWNOUT //Brownout reset - should always be used.
#FUSES NOJTAG //JTAG disabled
#FUSES PLLWAIT //Withg crystal, should always wait for this to be stable
#define S_LED PIN_A6
#define ETH_EN PIN_G14
#define PER_EN PIN_D5
#define PER_ON() output_high(PER_EN)
#define PER_OFF() output_low(PER_EN)
/* HW UART1 */
#pin_select U1RX=PIN_E1 // Rx Com1.
#pin_select U1TX=PIN_E0 // Tx Com1.
#define EN1_485 PIN_D1 // RE/DE Com1.
//=============== Debug UART1 =================
#use rs232(UART1,baud=115200,errors,enable=EN1_485,stream=DEBUG)
// Tick Timer3
#use TIMER(TIMER=3,TICK=1ms,BITS=16,NOISR)
#define TickDiff(a, b) (a-b)
void putc_debug(char c)
{
fputc(c, DEBUG);
}
#bit U1OTGSTAT_SESVD=getenv("BIT:SESVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD)
//cable attached for DsPIC
#include <usb_cdc.h> //Usb
// USB-CDC Vars.
#define _CR 0x0D
#define _LF 0x0A
#define U_STX 0x02
#define U_ETX 0x03
#define U_ACK 0x06
#define U_NAK 0x15
#define U_SP1 0x26 //'&'
#define U_SP2 0x3A //':'
#define URX_BUFF_SIZE 128
static int8 urx_buff[URX_BUFF_SIZE];
static int8 urx_index = 0;
static int1 FL_NEW_USB_PACKET = FALSE;
unsigned int8 UsbSeqEvnt = 0;
// ***** USB-CDC Task(). *****
void MyUsbTask(void)
{
char c;
if(usb_cdc_kbhit()){
c=usb_cdc_getc();
if(c == U_STX)
urx_index = 0;
else if(c == U_ETX)
FL_NEW_USB_PACKET = TRUE;
urx_buff[urx_index]= c;
if(++urx_index > URX_BUFF_SIZE-1) // usb_rx_buff overflow check**!
urx_index = URX_BUFF_SIZE-1;
printf(putc_debug,"char:'%c''\r\n", c);
}
// Get New Packet from USB-CDC Port ?
if(FL_NEW_USB_PACKET)
{
FL_NEW_USB_PACKET= FALSE;
urx_index = 0;
printf(putc_debug,"Packet\r\n");
}
}
void main(void)
{
unsigned int16 c_tick, p_tick; // timer Tick vars.
delay_ms(100); // Some startUp Delay..
PER_ON();
delay_ms(100);
usb_init();
enable_interrupts(GLOBAL);
while(TRUE)
{
usb_task();
c_tick = get_ticks();
if(usb_enumerated())
{
MyUsbTask();
if(TickDiff(c_tick, p_tick) > 1000)
{
output_toggle(S_LED);
p_tick = c_tick;
}
}
else
{ //Make this flash at a different speed so we know what is happening
if(TickDiff(c_tick, p_tick) > 10000)
{
output_toggle(S_LED);
p_tick = c_tick;
}
}
}
}
|
Key things here are:
Brownout enabled, in case you have a supply problem.
Flash speed will change if enumeration is lost.
Touch wood you can get some data as to what is really happening.
You did not answer about the hub in the USB connection?. The PIC33
has a major issue if there is a hub bringing the connection speed down.
Do need to check this. |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Tue Feb 25, 2025 6:43 am |
|
|
Hi,
1.With last add 'PLLWAIT' and 'BROWNOUT' same problem.
2. With and without usb hub also same problem. After send 10-30 packet with ten bytes USB block and start after reset mcu. |
|
 |
|