CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC USB to PC comms

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Liam_85



Joined: 09 Nov 2014
Posts: 26
Location: Ireland

View user's profile Send private message

PIC USB to PC comms
PostPosted: Mon Feb 13, 2017 3:55 am     Reply with quote

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: 19515

View user's profile Send private message

PostPosted: Mon Feb 13, 2017 4:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 13, 2017 2:48 pm     Reply with quote

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: 19515

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 2:41 am     Reply with quote

Good. Smile

The DTR one is a classic 'gotcha', when writing PC code to access the PIC, so I recognised the symptoms 'straight away'....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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