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

getc() not working at 16c745 well?

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

getc() not working at 16c745 well?
PostPosted: Thu Feb 10, 2005 3:34 pm     Reply with quote

I am using a getc() to get data from RS232 communication port. however, I could not make it work. following is the code


Code:

 while (TRUE)
    {
      usb_wait_for_enumeration();
      while(usb_enumerated())
      {
   
      printf("***Enumerated***\r\n");
    //  data=getc();
      putc('a');


if I did not mark off the data=getc()

the program just work for seval runs and stops.

any suggestions about this
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 4:27 pm     Reply with quote

Here is the output. after three circles, it hangs there

Quote:

0AWaiting for enumeration...***Enumerated***\0D
\0Aa***Enumerated***\0D
\0Aa***Enumerated***\0D
\0AInitialization!\0D
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 4:29 pm     Reply with quote

No last line, it was for the init of the usb at the begining

like this

0AWaiting for enumeration...***Enumerated***\0D
\0Aa***Enumerated***\0D
\0Aa***Enumerated***\0D
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

Give us something to work with!!
PostPosted: Thu Feb 10, 2005 4:31 pm     Reply with quote

Again the question we have asked you a number of times before:
How about showing us the code including the RS232 initialization. We are still not mind readers.
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 4:38 pm     Reply with quote

Thank you: here is the full testing code
Code:

#define USB_PIC16C765 1 //set to 1 to use a PIC16c765 USB Peripheral
                        //set to 0 to use a National USBN960x peripheral

#if USB_PIC16C765 //use the PIC16C7x5 peripheral
 #include <16C765.h>
 #device *=16
 #fuses HS,NOWDT,NOPROTECT
 #use delay(clock=24000000)

#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
#endif
//Tells the CCS PIC USB firmware to include HID handling code.

#DEFINE USB_HID_DEVICE  TRUE

//Set this to FALSE if you only want to test enumeration.  Some USB test programs,
//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED  TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE  1   //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8   //if you change this, be sure to change the hid descriptor

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE  1   //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE    2   //if you change this, be sure to change the hid descriptor

#if USB_PIC16C765
 #include "pic_usb.h"   //Microchip PIC16C765 hardware layer for usb.c


#include "usb.c"        //handles usb setup tokens and get descriptor reports
#include <stdio.h>
#include <stdlib.h>

int8 length,i, status;
char datar[20],packet[8][10],data;

void main() {
   int i;
   //data number status (dnums) and data complete status (dcoms)
   char dnums,dcoms;
   puts("Initialization!");
   usb_init();

   printf("\r\n\r\nWaiting for enumeration...");

   SETUP_CCP1(CCP_OFF);
   SETUP_ADC_PORTS(NO_ANALOGS);
    usb_wait_for_enumeration();
   while (TRUE)
    {
 
      while(usb_enumerated())
      {
      printf("***Enumerated***\r\n");
      data=getc();
      putc('a');
      putc(data);
}
}
}
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

Possible Framing Errors
PostPosted: Thu Feb 10, 2005 4:51 pm     Reply with quote

OK,
The first thing I see is you dont have the ERRORS parm in the RS232 line so it can recover from framing errors:

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

See if that helps.
Guest








PostPosted: Thu Feb 10, 2005 5:54 pm     Reply with quote

thank you:

You are very sharp, even the data received is not correct most of times, it do keep running right now. maybe I need some delay for right reading.

Why is ERRORS so important.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 7:06 pm     Reply with quote

One thing I would do is use KBHIT to test the UART to see if a char is present before calling getc():

if (kbhit)
data=getc();

What is the source for the RS232 input to the PIC?

If the baud rate of the sender is far enough off then the PIC UART will encounter framing errors on the incoming data.

Without the ERRORS parm the UART will hang when the error occurs waiting for your program to perform a recovery.

With the ERRORS parm the recovery happens automatically.
Guest








PostPosted: Fri Feb 11, 2005 7:41 am     Reply with quote

I am simulating a serial input from another PIC. this PIC send data to TWS434 and received by RWS434 wireless board. this USB pic receives data from RWS434. I used 16f819 instead of USB pic, and I got everything function well. right now I want to use USB pic instead of 16f819. and then this problem happened. the boud rate is 2400.
Guest








PostPosted: Fri Feb 11, 2005 8:37 am     Reply with quote

Thank you dyeatman:

The kbhit() is good it solved the problem and right now it is output data correctly.

why in some chip it works fine without errors and kbhit() , but some, like 16c745 need it? what is the trap here?
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 10:02 am     Reply with quote

Unfortunately without comparing the code for the other PIC and this one I am at a loss to explain it...but at least it works!!! One step forward!

dave
Guest








PostPosted: Tue Feb 22, 2005 7:15 pm     Reply with quote

what is wrong with this program? I put ERRORS, and used Khbit(), however, there is no output from the receiver side, some times just a dew space?

Code:
#if defined(__PCM__)
#include <16F819.h>
#include <stdio.h>
#include <stdlib.h>
#fuses HS,WDT,NOPROTECT
//#device ADC=10
#use delay(clock=10000000)
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1)

//sending
void main()
{
  char data[]="I am flying!";
   setup_port_a(ADC_OFF);
 
   setup_CCP1(CCP_OFF);
   setup_timer_1(T1_DISABLED);

   enable_interrupts(global);

   while(1)
   {
 
     putc('X');
     delay_ms(200);


  }
}



//receiving
#if defined(__PCM__)
#include <16F819.h>
#include <stdio.h>
#include <stdlib.h>
#fuses HS,WDT,NOPROTECT
//#device ADC=10
#use delay(clock=10000000)
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1,ERRORS)


void main()
{
  char data1[20],datar,ddl,ddh,datadecode;
  char status;  //data pre and post part
   setup_port_a(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_timer_1(T1_DISABLED);

   enable_interrupts(global);
   status=0;  //lsb part
   datadecode=0;
   while(1)
   {
   
   if ( kbhit() )
    {  datar = getc();
   //   delay_us(500);
     
      putc(datar);
    //  putc('a');
     
    }       
   }
}



tahnk you
Guest








PostPosted: Wed Feb 23, 2005 8:13 am     Reply with quote

I do not know anyhow it starts working!
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