|
|
View previous topic :: View next topic |
Author |
Message |
Donald_X
Joined: 08 Apr 2014 Posts: 9
|
|
Posted: Tue Apr 22, 2014 12:55 am |
|
|
Hi Ttelmah,
Adjustment of “send_message” function has helped with echo mode - program works fine now. But haven't fix timeout problem.
Do you think it could be caused by the old version of CCS compiler? Is it possible that in my version could be some bug that is causing the problem?
Thanks
Daniel |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Apr 22, 2014 3:39 am |
|
|
It's possible, but perhaps not totally likely.
Your own diagnosis, suggests that the PIC is actually responding correctly or near correctly, which was more like problems I had with chipset USB drivers.
One thing that might give an intermittent problem is the smoothing of Vusb. This is much more critical than is often thought. If the capacitor is too large, the bus doesn't wake up quickly enough, but too small, and you get tiny 'oddities' in the USB behaviour with unreliable operation. Key is it's HF performance. Something like a 470nF polyester capacitor seems the 'best' solution. 220nF can be a little small (data sheet minimum). Might be worth just changing what you use here and see if it has any effect. |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Wed May 21, 2014 6:11 am |
|
|
Hiii,
I am using 18F26J50, and i am trying implement USB, but its showing the device not recognized,
Can any one help with a working code and oscillator configuration, i think my oscs configuration is creating pblm |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed May 21, 2014 6:53 am |
|
|
Hi,
First of all, you should tell us your crystal frequency. Then you should post your suspect configuration for us to look at. Without this information, we are only just guessing at what your problem might be!
If you *do* suspect an oscillator problem, connect an LED to an I/O pin of the PIC, and flash it at a known rate, say 1 second On, and 1 second Off. This will either work as expected, or you will observe a gross deviation in the timing. Check it out yourself!
John |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Wed May 21, 2014 8:23 am |
|
|
Code: | #FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#FUSES HSPLL
#FUSES PLL1
#FUSES RTCOSC_INT
#use delay(clock=48000000) |
The above given is my fuse settings,using external 4MHz crystal and using PLL clock 48MHz. |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Wed May 21, 2014 8:25 am |
|
|
I have connected an led, its working properly,but settings for usb i think its wrong |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Wed May 21, 2014 8:26 am |
|
|
This is my code,
Code: | #include <18F26J50.h>
#FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#FUSES HSPLL
#FUSES PLL1
#FUSES RTCOSC_INT
#use delay(clock=48000000)
#ZERO_RAM
#include <stdio.h>
#include <stdlib.h>
#define USB_CON_SENSE_PIN PIN_B7 //Voltage level converted
#include <usb_cdc.h>
#define USB_EXTERNAL_PULLUPS
void main()
{
int i, j, address, value;
setup_oscillator(OSC_PLL_ON);
output_high(pin_c2);
enable_interrupts(GLOBAL);
output_high(pin_c2);
usb_init_cs();
while(1)
{
usb_task();
if (usb_enumerated())
{
output_high(pin_c2);
delay_ms(500);
output_low(pin_c2);
delay_ms(500);
if (usb_cdc_kbhit())
{
output_high(pin_c2);
delay_ms(500);
output_low(pin_c2);
delay_ms(500);
}
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Wed May 21, 2014 9:03 am |
|
|
There is a possible disagreement in your fuses.
You have HSPLL selected, which is normally used for a crystal above 4MHz, can overdrive if used at 4Mhz. But then you have PLL1 selected, which only applies with a 4MHz crystal.
Do you have the external pull up?. You have external pull ups selected. You need a 1.5K resistor from D+, to Vusb.
Are you feeding Vusb?.
Get rid of the setup oscillator line. The PLL enable, only applies when using INTOSCPLL mode, where the PLL can be software controlled.
Don't delay in the master loop. If you want to do flashing LED's etc., then use a timer, and handle these with this. There are problems if usb_task is not called at regular intervals. Even with interrupt driven handling, it should be called quite frequently...
When kbhit goes true, you need to read the received character, or the buffer will eventually overflow.... |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Thu May 22, 2014 12:30 am |
|
|
Thank you Ttelmah,
Now I have got connected the usb to PC, but it's unable for me to see the data I am transmitting, what will be the baudrate for the usb to uart ?
My code:
Code: |
#include <18F26J50.h>
#FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#FUSES HSPLL
#FUSES PLL1
#FUSES RTCOSC_INT
#USE fixed_io(c_outputs = PIN_C2, PIN_C3)
#use delay(clock=48000000)
#define CMD_length 20
char msg2[]="Hi Renjith,Its USB";
//A5 old B2 new
#define SL_LED_ON {output_high( PIN_C2);}
#define SL_LED_OFF {output_low( PIN_C2);}
#define LED_ON {output_high( PIN_C2);}
#define LED_OFF {output_low( PIN_C2);}
#define USB_CONFIG_BUS_POWER 100 //300mA (range is 0..500)
#include<usb_desc_cdc.h>
#include <usb_cdc.h>
unsigned long cmd_counter = 0;
void main()
{
int i, j, address, value;
setup_oscillator(OSC_PLL_ON);
output_high(pin_c2);
enable_interrupts(GLOBAL);
output_high(pin_c2);
usb_init();
while(1)
{
usb_cdc_init();
usb_task();
if (usb_enumerated())
{
usb_cdc_connected();
while(1)
{
output_high(pin_c2);
usb_cdc_puts(msg2);
delay_ms(100);
output_low(pin_c2);
delay_ms(100);
}
if (usb_cdc_kbhit())
{
output_high(pin_c2);
delay_ms(500);
output_low(pin_c2);
delay_ms(500);
}
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu May 22, 2014 1:00 am |
|
|
There isn't a baud rate.
USB to UART runs at the USB speed (limited by packets, timing etc.). When you set the baud rate, all it does is send a packet to the slave device saying 'this is the baud rate being used', so that if it is implementing an external serial connection, the device can change the baud rate on this. The USB communication remains unchanged.
Are you still running with a 4MHz crystal?.
I'd suggest 'not' doing this. Have had problems in the past with the PLL, running from 4Mhz, being slightly unreliable. It appears that if the crystal is a bit overdriven (with HSPLL your's almost certainly _will_ be), you get an asymmetric waveform from the oscillator, that then causes problems with the PLL. By adding a series resistor to the crystal, to bring the drive down, and switching to XTPLL, it is possible to get it working, but is still a fiddle. Running off an 8Mhz crystal, with PLL2 is generally much more reliable.
You also have not got rid of the setup_oscillator line. OSC_PLL_ON, _does not apply with the crystal drive_.
You are also still delaying too much in the loop, and not reading the character if received. |
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Thu May 22, 2014 4:55 am |
|
|
Here I am not using any other device for communication. I am connecting it with PC using tiny bootloader for checking serial. There its showing com6, but not receiving any data. But when i send data from PC, its reaching the controller, for that i have made an led off. But I don't what's the problem. I have written for reading and writing the same data to PC, but its not working. Anyway i will change my crystal to 8MHz ok.
Thank you Ttelmah.
Code: | if (usb_cdc_kbhit())
{
x=usb_cdc_getc();
delay_us(50);
usb_cdc_putc(x);
output_low(pin_c2);
} |
|
|
|
Renjith_Beginow
Joined: 21 May 2014 Posts: 12
|
|
Posted: Fri May 23, 2014 3:10 am |
|
|
I have got communication with PC but data is not continuously receiving by system, after one or two characters, commnication loss, but connection will be there, What will be the reason.
Code: |
#include <18F26J50.h>
#FUSES NOWDT
#FUSES NODEBUG
#FUSES NOXINST
#FUSES NOPROTECT
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOCPUDIV
#FUSES HSPLL
#FUSES PLL2
#FUSES RTCOSC_INT
#USE fixed_io(c_outputs = PIN_C2, PIN_C3)
#define USB_CONFIG_HID_TX_SIZE 8
#define USB_CONFIG_HID_RX_SIZE 8
#use delay(clock=48000000)
#define CMD_length 20
char msg2[]="Hi Renjith,Its USB";
//A5 old B2 new
#define SL_LED_ON {output_high( PIN_C2);}
#define SL_LED_OFF {output_low( PIN_C2);}
#define LED_ON {output_high( PIN_C2);}
#define LED_OFF {output_low( PIN_C2);}
#define USB_CONFIG_BUS_POWER 100 //300mA (range is 0..500)
#include<usb_desc_cdc.h>
#include <usb_cdc.h>
unsigned long cmd_counter = 0;
#define USB_CON_SENSE_PIN PIN_B7
char x;
char out_data[USB_CONFIG_HID_TX_SIZE];
char in_data[USB_CONFIG_HID_RX_SIZE];
void usb_debug_task(void) {
static int8 last_connected;
static int8 last_enumerated;
int8 new_connected;
int8 new_enumerated;
new_connected = usb_attached();
new_enumerated = usb_enumerated();
last_connected = new_connected;
last_enumerated = new_enumerated;
}
void main(void)
{
int i, j, address, value;
memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);
setup_oscillator(OSC_PLL_ON);
output_high(pin_c2);
enable_interrupts(GLOBAL);
output_high(pin_c2);
usb_init();
delay_us(100);
usb_cdc_init();
delay_us(100);
while(1)
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
output_high(pin_c2);
//usb_put_packet(1, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);
if (usb_cdc_kbhit())
{
output_low(pin_c2);
x=usb_cdc_getc();
delay_us(50);
usb_cdc_putc(x);
delay_us(50);
if (usb_cdc_put_buffer_nextin && usb_cdc_put_buffer_free())
{
usb_cdc_flush_out_buffer();
}
delay_us(50);
}
}
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Fri May 23, 2014 5:22 am |
|
|
just jumping in here but...
...if I'm reading your code right...
I'd edit the delay_us(50); lines to delay_ms(100); for testing
50 microseconds is mighty fast...might be way too fast for either the PIC or the PC to deal with(you don't KNOW which yet). By slowing down the 'loop'(rcv---xmt) you stand a chance of seeing characters on the PC screen.
When I test any serial link, I go 'turtle slow' to confirm hardware and software is working, then up it to 'human' then to 'rabbit' when I am convinced I can.
hth
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 23, 2014 6:50 am |
|
|
Hi Renjith_Beginow,
You need to seriously step back and re-evaluate your appraoach! Your current code is a mix of CDC and HID implementations, so clearly you aren't trying to understand what's going on, but rather you are just throwing random code at the problem trying to get something to work......
Seriously, take a look at the CCS supplied USB CDC examples (usb_cdc_serial2.c is a good place to start!) and begin there. These examples work as supplied, and you can build on them from there!
Your 'franken-code' is never going to work as written.....
John
PS Learn to use the 'Code' buttons. No one is going to take you seriously unless you can do that basic function...... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Fri May 23, 2014 7:11 am |
|
|
It is Franken-code.... Like the title...)
Thinks leap out like:
usb_cdc_put_buffer_nextin, which is a count, being used in a logic test...
This looks to be copied from the putempty macro, where there is an ==0 being omitted in what is pasted..... |
|
|
|
|
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
|