Reputation: 21
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);}
}
Upvotes: 2
Views: 1508
Reputation: 1
Maybe this helps:
usb_cdc_getc()
- Gets a character from the receive buffer. If there is no data in the receive buffer it will wait until there is data in the receive buffer. If you do not want to wait in an infinit loop, useusb_cdc_kbhit()
first to check if there is data before callingusb_cdc_getc()
."
from https://github.com/tkrworks/PICnome-Firmware/blob/master/usb_cdc.h
Upvotes: 0
Reputation:
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.
Upvotes: 1