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

Serial comm's over USB, how do I send commands over hyperter

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



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

Serial comm's over USB, how do I send commands over hyperter
PostPosted: Mon Jul 10, 2006 4:58 am     Reply with quote

Hi all, I'm very new to all of this, basicly im trying got code written in MPLAB using the CCS compiler, and im using the CCS windows driver, when i connect the USB cable it is detected and the driver installs fine. For the application the USB is being used for a virtual Serial connection to the PC, I want to send some cammands using hyperterminal but it will not connect to my hardware?? I cant work out why, anyone got any ideas?

Cheers all, Jon Question
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Mon Jul 10, 2006 10:21 am     Reply with quote

I realise that its a stupid question but i've been kind of dropped in the deep end and im out of my depth this all this stuff, i just need to know how to talk to the pic in hyperterminal, i have a virtual com port, which is the pic (com3) but hyperterminal says unable to connect, help please! Crying or Very sad
Fro_Guy



Joined: 26 Apr 2006
Posts: 12

View user's profile Send private message

PostPosted: Mon Jul 10, 2006 2:29 pm     Reply with quote

Sounds like proplbems with hyper terminal, try to open the port with brays terminal and make sure all the port setting are set correctly
http://bray.velenje.cx/avr/terminal/
If that dosent work i would have to say that your drivers arn't working properly, and i have no experance with the CCS Drivers.

Good luck
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Tue Jul 11, 2006 2:07 am     Reply with quote

Hi, thanks very much for the reply, I am using the CCS driver, im not totally sure what settings I should be using in hyperterminal, and i'm not clear as to what the #use RS232 line in the code should be set too, do I need to asign the pins used for the USB in the use rs232 line? I'm getting so confused.... Shocked
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Tue Jul 11, 2006 11:44 am     Reply with quote

Have you looked at the serial examples that were written for the USB CDC?
ex_usb_serial2.c and ex_usb_serial.c in particular show exactly how to setup and use it. The only reason I say this is because of the question on the #use RS232, it is not needed to communicate serially over the USB. I would make sure that you can receive something over Hyperterminal first to make sure that the PIC is functional. So try outputing a string in a loop with a couple second delay between. I used 9600 8 n 1 for my setup, and had no problems.
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Wed Jul 12, 2006 1:51 am     Reply with quote

Hi, thatks for the relpy, yes i've tried the two examples and I havn't got either to work so far, I presume when you plug the USB cable into the PIC it should load the CCS Driver? When you used 9600 baud, etc, did you set that in the code or is that just the default settings you can use for hyperterminal with this program?
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Wed Jul 12, 2006 9:00 am     Reply with quote

One other thing is that if you can't get Hyperterminal to work, try using the Serial Port Monitor that comes with the CCS Compiler.

I just made sure that Hyperterminal was setup just like this little bit of code that is found 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_put_buffer_free=TRUE;
}


Have you tried receiving any thing from the PIC to Hyperterminal yet? That is where I would start if you are having issues. If you can't receive anything, transmitting isn't going to work either. This will let you know if the problem is in you code on the PIC or if Hyperterminal has an issue.

I would get one of the examples working first as they should work without any modification and then go from there. Without seeing any of your code, that's where I would start.


--Edit--
Which chip are you using? Are you using the USB Development Kit? One other thing, just guessing from your comments, it looks like you are trying to get the ex_usb_serial.c example to work. Make sure that you read the notes at the top of the file as they explain how to setup Hyperterminal and how to use the example.
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Thu Jul 13, 2006 1:44 am     Reply with quote

Thats great, thanks for your detailed reply, basicly i'm not using a development board, I have firmware for the PIC that was writen by a colegue which has never been tried on a PIC, and they have now left the company, so it is up to me (with my VERY basic PIC knowledge) to get it working and debug it, however I do have a microchips PICDEM FS USB DemoBoard, http://ww1.microchip.com/downloads/en/DeviceDoc/51526a.pdf, (this is the user guide for this board) It uses the same PIC i'm using (PIC18F4550) and it has USB and runs on a 20mhz crystal. Has anyone writen an example using the CCS compiler for this board?

As for the hyperterminal setup, I did read the info at the top of the examples but it confused me, am I suposed to open two hyperterminal windows? and why am I supposed to open one using the COM port assigned to my RS232 port on the PC? I relise its probably simple but unfortunatly so am I Wink
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Thu Jul 13, 2006 3:07 am     Reply with quote

ok exciting developments at my end, I have used the ex_usb_serial.c program and modded it slightly to work on my PICDEM board and it works! I think, well it prints: CCS CDC (Virtual RS232) Example, and thats about it, here is the code i've used:

Code:
#define __USB_PIC_PERIF__ 1

#if !defined(__PCH__)
 #error USB CDC Library requires PIC18
#endif


#DEFINE LED1  PIN_D1
#include <18F4550>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN, NOMCLR
#use delay(clock=48000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#include <usb_cdc>

/////////////////////////////////////////////////////////////////////////////
//
// Configure the demonstration I/O
//
/////////////////////////////////////////////////////////////////////////////
#define LED2 PIN_D2
#define LED3 PIN_D3
#DEFINE BUTTON PIN_B4
#define LED_ON output_low
#define LED_OFF output_high


/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.
//
/////////////////////////////////////////////////////////////////////////////
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();
   new_cdc=usb_cdc_connected();

   if (new_enumerated)
      LED_ON(LED1);
   else
      LED_OFF(LED1);

   if (new_cdc)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

   if (usb_cdc_carrier.dte_present)
      LED_ON(LED3);
   else
      LED_OFF(LED3);

   if (new_connected && !last_connected)
      printf("USB connected, waiting for enumaration...\r\n\n");
   if (!new_connected && last_connected)
      printf("USB disconnected, waiting for connection...\r\n\n");
   if (new_enumerated && !last_enumerated)
      printf("USB enumerated by PC/HOST\r\n\n");
   if (!new_enumerated && last_enumerated)
      printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
   if (new_cdc && !last_cdc) {
      printf("Serial program initiated on USB<->UART COM Port\r\n\n");
      printf(usb_cdc_putc, "\r\n\nCCS CDC (Virtual RS232) Example\r\n\n");
   }

   last_connected=new_connected;
   last_enumerated=new_enumerated;
   last_cdc=new_cdc;
}

void main(void) {
   char c;

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nCCS CDC (Virtual RS232) Example\r\n");

  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init_cs();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif


   while (TRUE) {
      usb_task();
      usb_debug_task();

      if (kbhit()) {
         c=getc();
         if (c=='\n') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         if (c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}
      }
      if (usb_cdc_kbhit()) {
         c=usb_cdc_getc();
         if (c=='\n') {putc('\r'); putc('\n');}
         if (c=='\r') {putc('\r'); putc('\n');}
         else {putc(c);}
      }
   }
}


And in hyperterminal I used 9600, 8, n, 1

The driver I used was actually the driver the guy who wrote the code im supposed to be debugging wrote, which driver should this example use? the USB UART, or the USB RS232?

Cheers
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Thu Jul 13, 2006 3:31 am     Reply with quote

Ok another stupid question, where does the program "printf" to?

printf(usb_cdc_putc, "\r\n\nCCS CDC (Virtual RS232) Example\r\n\n");

this is the line that is printed to hyperterminal, presumably because it has usb_cdc_putc infront of it? but where are the other printf's sent too?
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Thu Jul 13, 2006 4:08 am     Reply with quote

Don't worry after more fiddling I can answer my own question and I now understand the hyperterminal (two window thing) I have RS232 out of the PIC into the PC now and the USB and both are talking so i'm finnaly getting somewhere, cheers for your continuing help jspencer Smile
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Thu Jul 13, 2006 11:12 am     Reply with quote

It sounds like you got it figured out. It is a little confusing as that example is using the RS232 port and a virtual COM port (USB). Glad you got it figured out. You should be well on your way now.
Jon



Joined: 10 Jul 2006
Posts: 9
Location: Fordingbridge

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Fri Jul 14, 2006 1:41 am     Reply with quote

Thanks for all your help jspencer, these forums just wouldn't work without the knowledge of people such as your self, Thanks again, Jon
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