View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 218
|
[closed] 18F47J53 as usb-serial programmer not reliable :( |
Posted: Mon Nov 28, 2016 3:16 am |
|
|
Hello,
On a new project, I'm using a 18F47J53 and an ESP8266.
I would like to update the esp8266 through the pic using USB to serial.
I tried the USB to serial example, but it looks like it's not really reliable: it start but crash before end :(
Is there another example to do just USB to serial but maybe more complex but more reliable ?
Thanks for your help
Last edited by spilz on Wed Dec 07, 2016 7:47 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19491
|
|
Posted: Mon Nov 28, 2016 4:29 am |
|
|
Used right, the standard usb-serial is 99.999999% reliable.
I've had systems running for months without a single byte problem.
Things that have to happen:
1) Smooth/reliable supply. especially to the Vusb pin.
2) Reliable USB clock. Are you using a crystal, or synchronising to the USB clock?. Are you sure you have this configured correctly?.
3) Enough buffering and/or flow control. If you are programming a device that takes time to accept data, can the PIC store data that is likely to arrive while this is happening?. If not, then it needs to stop the transaction.
4) If you are not powered off USB, then you must use USB connection sense. This is specified in the USB paperwork, and is often misunderstood.
5) Well designed USB connections. Problems can easily be caused by a bad impedance match on the USB tracks, too much length, or a length imbalance on the tracks.
6) Dozens of other things..... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Mon Nov 28, 2016 5:18 am |
|
|
my hardware is :
power : by USB -> AMS1117-3.3V to convert 5v(usb) to 3.3V with 100nf and 10uF capacitors before and after.
Quartz : 4MHz cristal using PLL1 and running at 48MHz
Vusb : connected to 3.3v and with a 470nF to ground
D- and D+ tracks are short (7mm), they have the same length and same form, they stay parallele.
Did I something wrong ?
The USB-Serial works at the beginning but after some transfert, the PIC freezes :(
thanks for your help |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Mon Nov 28, 2016 5:58 am |
|
|
Am I right in assuming the USB side of the PIC goes to a PC ?
If so, there's a LOT of 'stuff' in/on a PC that can cause 'problems'! Depending on the OS version, open, running programs, hidden auto-update software, auto-save programs, internet programs like autoget emails, etc.
As Mr. T says the PIC USB is really stable...
My main development PC is NOT on the net, NO updates, and JUST runs CCS C, through MPLAB 8v86. I use Realterm for USB/RS232 terminal stuff, Delphi for access/control programming.
Jay |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Mon Nov 28, 2016 6:34 am |
|
|
you are right, it's to connect to a PC.
but in my case, I don't really have choise : would like to use it to program an ESP8266 through Arduino IDE, so I need it works like a classic USB<->serial.
during this part, the pic does nothing else |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Mon Nov 28, 2016 7:36 am |
|
|
We will have to see the PIC code...
I'm thinking maybe the WDT is enabled or 'flowcontrol' on the PC/USB side isn't correct.
Or a Windows 'issue'? Which OS are you running/mode?
Can you use the PIC in 'loopback' mode?
IE: PC terminal program sends characters to USB->PIC, PIC reads then sends back those characters to USB/PC terminal program and get displayed on screen properly ?
Really need to see if it's hardware or software and where the issue is.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19491
|
|
Posted: Mon Nov 28, 2016 8:57 am |
|
|
I'd be suspicious of power and then handshaking. This unit draws a _lot_. When run off an Arduino for example you have to use a separate power supply, since the internal supply from USB cannot deliver enough. You may have a 1A regulator, but the USB port is only rated to deliver 500mA, and that only if you have turned up the power requirements in the USB files to maximum....
Other really likely thing is that a pause is needed during programming, and therefore handshaking is needed.
Have a look at this post:
<https://www.baldengineer.com/four-esp8266-gotchas.html> |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Mon Nov 28, 2016 4:19 pm |
|
|
I'm using a USB HUB with an external power supply, I don't think the issue comes from the power, and AMS1117 can provide more than 1A, and in programming mode the ESP does not use so much power.
there are 2 points I miss understand I guess :
- when using RECEIVE_BUFFER in Code: | #use rs232(UART1, baud=INIT_UART_BAUDRATE, stream=STREAM_UART1, RECEIVE_BUFFER=250, errors) | does interrupt #INT_RDA works ? or only when buffer is full ?
- I tried other stuff with USB to serial, just trying to send data from PIC -> PC, but it works one time, and after the PIC freezes :(
My project uses these interrupts : #INT_EXT1 #INT_RDA #INT_RDA2
what is the simplest code to send data through USB ?
What Should I do with interrupts ?
Code: | enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
ext_int_edge( 1, L_TO_H);
enable_interrupts(INT_EXT1);
enable_interrupts(GLOBAL);
usb_cdc_init();
while(true){
usb_task();
usb_enumerated();
LED_R(usb_cdc_carrier.dte_present);
printf(usb_cdc_putc,"Send\r\n");
} |
I got these warnings when I compile, maybe it can help :
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_token_reset)
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_get_discard)
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_flush_tx_buffer)
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_tbe)
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (@GETCH_BIU_1)
>>> Warning 216 "18F47J53_ESP.c" Line 355(1,2): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_init)
I don't use USB in interrupts |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Mon Nov 28, 2016 5:06 pm |
|
|
You say your program uses 3 interrupts. Do ALL of them have handlers (code) IF enabled ?
While I don't use that PIC (none with internal USB) I can have a 46K22 connected to as PC on both hardware UARTS <>USB modules and run 115K200 all day long using the ex_sisr.c example that CCS supplies.
Since your PIC 'freezes' you must have some hard or soft 'issue'. Time to go back to basics, get rid of all code but a simple 'loopback' program.
Jay |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Tue Nov 29, 2016 4:55 am |
|
|
after test, it looks like sending data from PIC to PC is the problem :
with just this code : Code: | int cmp = 0;
usb_init_cs();
while(true){
usb_task();
usb_attached();
if(usb_enumerated() && usb_cdc_carrier.dte_present){
output_toggle(led);
printf(usb_cdc_putc,"testing sending data %u",cmp++);
delay_ms(1000);
}
} |
it works almost 20 times then freeze ...
any idea ?
thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19491
|
|
Posted: Tue Nov 29, 2016 5:25 am |
|
|
Are you enabling interrupts (GLOBAL)?.
If not, then USB_task needs to be called every few mSec. Even if they are enabled, USB_task needs to be called at a reasonable frequency. You never call it after the start.
USB_task handles the 'housekeeping' for USB. Without this things _will_ go wrong.
Code: |
int cmp = 0;
usb_init_cs();
while(true){
usb_task();
//usb_attached(); //USB_attached is a function you _test_
enable_interrupts(GLOBAL);
if (usb_enumerated() && usb_cdc_carrier.dte_present)
{
output_toggle(led);
printf(usb_cdc_putc,"testing sending data %u",cmp++);
delay_ms(1000);
usb_task();
}
|
usb_attached, is like usb_enumerated. It returns 'true' if the cable is attached to the system, It is not something you call except to test this. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Tue Nov 29, 2016 6:36 am |
|
|
I still have the issue with this code :
Code: | int16 cmp = 0;
int c = 0;
usb_init_cs();
while(true){
usb_task();
enable_interrupts(GLOBAL);
if (cmp++ > 1000 && usb_enumerated() && usb_cdc_carrier.dte_present)
{
cmp = 0;
output_toggle(led);
printf(usb_cdc_putc,"testing sending data %u",c++);
}
delay_ms(1);
} |
but I don't have it if I useinstead of Code: | printf(usb_cdc_putc,"testing sending data %u",c++); |
looks like the issue is from printf(usb_cdc_putc,... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 218
|
|
Posted: Tue Nov 29, 2016 7:17 am |
|
|
I tried Quote: |
if (cmp++ > 1000 && usb_enumerated() && usb_cdc_carrier.dte_present)
{
cmp = 0;
output_toggle(led);
usb_cdc_putc('T');
usb_cdc_putc('E');
usb_cdc_putc('S');
usb_cdc_putc('T');
usb_cdc_putc('I');
usb_cdc_putc('N');
usb_cdc_putc('G');
usb_cdc_putc(' ');
usb_cdc_putc('D');
usb_cdc_putc('A');
usb_cdc_putc('T');
usb_cdc_putc('A');
} |
I still have the issue.
So it looks like I can't send few datas every few seconds :( any idea ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19491
|
|
Posted: Tue Nov 29, 2016 8:08 am |
|
|
What compiler version are you on?.
There was an issue with the early V5 compilers disabling interrupts in printf. |
|
|
|