 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Wed Aug 19, 2015 3:34 am |
|
|
Take a step back.
Try running one of the example programs like the ex_usb_serial.c
Try sending this data from a terminal package, and verify it echo's back. Try typing for a minute or two, and see if it stops.
If it does, there is a hardware problem. A spike or something. If however it keeps working, then you have narrowed the problem down to being something in the software. |
|
 |
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Wed Aug 19, 2015 10:15 pm |
|
|
Hi Ttelmah,
Thank you very much for ex_usb_serial.c idea. It works perfectly!!!.
I've modified the example and it also works without any com disconnecting problem. However i need to add command below to make it works:
| Code: |
If(usb_cdc_kbhit())
{
c=usb_cdc_getc();
if (c=='\n') {putc('\r'); putc('\n');}
if (c=='\r') {putc('\r'); putc('\n');}
|
What is this command purpose? Hope you explain to me. My code as shown below:
| Code: |
#include <18F4550.h>
#fuses HSPLL,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include <string.h>
#include <input.c>
#include <stdio.h>
#include <stdlib.h>
#include <usb_cdc.h>
void main(void)
{
int8 binary_string[10];
char c;
usb_init_cs();
while(TRUE)
{
usb_task();
If(usb_cdc_kbhit())
{
c=usb_cdc_getc();
if (c=='\n') {putc('\r'); putc('\n');}
if (c=='\r') {putc('\r'); putc('\n');}
while(true)
{
printf(usb_cdc_putc,"Enter 8 binary number : \n");
get_string_usb(binary_string,9);
output_D((int8)strtoul(binary_string,0,2));
}
}
}
} |
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Thu Aug 20, 2015 2:39 am |
|
|
kbhit, is exactly like the normal RS232 kbhit. It returns 'true' if a character has arrived on the link.
Adding this means the code won't go into your numeric 'wait' loop, till data has actually been seen arriving. Means that usb_task will be continuously called, _until_ this has happened.
As I've said before, usb_task does some USB housekeeping, and it looks as if stopping this housekeeping before data has arrived, leads to a problem. |
|
 |
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Thu Aug 20, 2015 4:08 am |
|
|
Hai Ttelmah,
Thank you very much once again for your explanation.
Problem solve  |
|
 |
|
|
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
|