View previous topic :: View next topic |
Author |
Message |
Liam_85
Joined: 09 Nov 2014 Posts: 26 Location: Ireland
|
PIC USB to PC comms |
Posted: Mon Feb 13, 2017 3:55 am |
|
|
Hello everyone,
Does anybody have any insight into talking to a PIC from the PC via USB. I have a USB PIC - PIC18F45K50 with an on-board USB peripheral. I currently have the USB example ex_usb_serial on the PIC and I can talk to it using either terminal programs RealTerm and Teraterm. However when i use a C# GUI that I built earlier (which is confirmed working with both FTDI and SiLabs CP2102 USB to UART modules) it just hangs. Is there something I am missing? I found this function in the usb_cdc.h file:
Code: | void usb_cdc_init(void)
{
usb_cdc_line_coding.dwDTERrate = 9600;
usb_cdc_line_coding.bCharFormat = 0;
usb_cdc_line_coding.bParityType = 0;
usb_cdc_line_coding.bDataBits = 8;
(int8)usb_cdc_carrier = 0;
usb_cdc_got_set_line_coding = FALSE;
usb_cdc_break = 0;
usb_cdc_put_buffer_nextin = 0;
usb_cdc_get_buffer_status.got = 0;
__usb_cdc_state = 0;
} |
I have matched the serial port settings in C# to this but still nothing. I have been Googling this for a few days to no avail. If anybody has any experience with this or can point me in the right direction it would be greatly appreciated. Thanks.
Oh by the way my compiler version is: 5.054 _________________ Liam Hanmore |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 13, 2017 4:52 am |
|
|
You need to ensure DTR is set when you want to use the port.
The CCS example, looks to see if DTR is set, before it'll allow comms (correct RS232 handling...). The terminal packages all set this automatically. A lot of USB ports "don't bother" about it.
DtrEnable property. |
|
|
Liam_85
Joined: 09 Nov 2014 Posts: 26 Location: Ireland
|
|
Posted: Mon Feb 13, 2017 2:48 pm |
|
|
Thank you very much Ttelmah, worked straight away!
The other issue I had which was resolved thanks to a comment you posted in another topic about using the internal RC oscillator instead of the external oscillator with PLL. I didn't check the manufacturer of the crystal to use the correct caps and because (I think) the USB timings was slightly off. Changing to the internal RC oscillator resolved it so thanks again.
Needless to say, this is my first experience of PICs with USB peripherals! _________________ Liam Hanmore |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Feb 14, 2017 2:41 am |
|
|
Good.
The DTR one is a classic 'gotcha', when writing PC code to access the PIC, so I recognised the symptoms 'straight away'.... |
|
|
|