tags:

views:

67

answers:

1

Hi all, I'm programming a PIC18F4455 Microcontroller using PIC C. I'm using the USB_CDC.h header file. I have a program on the computer sending a string such as "W250025". However, when I use usb_cdc_getc() to get the first char, it freezes. Sometimes the program sends only 'T', so I really want to just get the first character.

Why does my code never execute past received=usb_cdc_getc(); when I send "W250025"?

if (usb_cdc_kbhit())
      {
         //printf(lcd_putc, "Check 3"); delay_ms(3000); printf(lcd_putc, "\f");
         received = usb_cdc_getc();
         printf(lcd_putc, "Received "); lcd_putc(received); delay_ms(3000); printf(lcd_putc, "\f");
         if (received == 'W'){   //waveform
            disable_interrupts(INT_TIMER1);
            set_adc_channel(0);
            load_and_print_array(read_into_int(), read_into_int());}
         else if (received == 'T'){ //temperature
            set_adc_channel(1);
            enable_interrupts(INT_TIMER1);}
      }
+1  A: 

I don't know the specifics of the PIC microcontroller, but, assuming that usb_cdc_getc behaves like the normal getc, the most likely cause is that your characters aren't reaching the function, which normally blocks. Are you sending a newline? It could also be a hardware problem where the characters aren't reaching your uC in the first place.

If it is the former, and not the desired behavior there likely is a nonblocking getch equivalent.

jbcreix