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 support@ccsinfo.com

ex_usb_serial example for Microchip PICDEM FS USB demo board

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



Joined: 05 Oct 2015
Posts: 2

View user's profile Send private message

ex_usb_serial example for Microchip PICDEM FS USB demo board
PostPosted: Mon Oct 05, 2015 9:35 am     Reply with quote

Hi all,

I am relatively new to USB and am having problems running the ex_usb_serial example with the Microchip PICDEM FS USB demo board (the 18F45K50 version).
When I plug the board into my PC, the device is recognised ok as a 'CCS USB to UART' COM9 port and USB enumeration is successful as indicated by LED 1. When I open the 2 hyperterminals (COM1 and COM9) as described in the example, LEDs 2 and 3 both appear to indicate setup successfully. However, none of the setup messages appear in either of the hyperterminals, nor does typing a character in COM1 appear on COM9.

The only part of the code I have slightly modified to get any of it working was to add the following hardware and config definitions into ex_usb_common.h for my specific dev board. (the PIC18F45K50 uses its own internal FRC (Fast RC) oscillator
running at 16 MHz along with a 3X PLL to achieve the required 48 MHz).
Code:

#include <18F45K50.h>
 
#fuses NOWDT, PLLEN, PLL3X, INTRC       
 #use delay(clock=48MHz,USB_FULL)
 setup_oscillator(mode = OSC_16MHZ|OSC_INTRC|OSC_PLL_ON|OSC_PLL_3X);
 
   #DEFINE LED1 PIN_D0 
   #define LED2 PIN_D1 
   #define LED3 PIN_D2
   #define LEDS_OFF()   LED_OFF(LED1); LED_OFF(LED2); LED_OFF(LED3)
   #define BUTTON_PRESSED() !input(PIN_B4)

   #define PIN_USB_SENSE   PIN_A1

   #define HW_ADC_CONFIG   ADC_CLOCK_INTERNAL
   #define HW_ADC_CHANNEL  0  //PIN_A0
   #define HW_ADC_PORTS    sAN0
   
   #define HW_INIT() setup_adc_ports(HW_ADC_PORTS)

Any help with this would be much appreciated,

Many thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19448

View user's profile Send private message

PostPosted: Mon Oct 05, 2015 10:10 am     Reply with quote

Key thing missing. You need to turn on ACT.

You can't actually run the USB directly from the internal 16MHz clock. It isn't accurate enough. What ACT does, is automatically synchronise the internal clock to the clock on the USB bus when you connect, so the clock becomes based on the USB clock. You need to add ACT=USB to the clock setting, which then makes this happen.

Also, since you are using setup_oscillator, on the next line add:
setup_act(ACT_ENABLED | ACT_TUNED_TO_USB);

to ensure it is left on after the oscillator changes.
stod



Joined: 05 Oct 2015
Posts: 2

View user's profile Send private message

PostPosted: Thu Oct 08, 2015 4:48 am     Reply with quote

Many thanks for your help.

Unfortunately I am still having the same problem. I added/amended the following code as suggested.

Code:
#include <18F45K50.h>
  #fuses NOWDT, PLLEN, PLL3X, INTRC       
  #use delay(int=16MHz, clock=48MHz,USB_FULL, ACT=USB)
  setup_oscillator(mode = OSC_16MHZ|OSC_INTRC|OSC_PLL_ON|OSC_PLL_3X);
 setup_act(mode  = ACT_ENABLED | ACT_TUNED_TO_USB);

Any further suggestions would be much appreciated.

Many thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19448

View user's profile Send private message

PostPosted: Thu Oct 08, 2015 7:06 am     Reply with quote

Start by doing some debugging. Check that your COM3 to the PIC is working, Forget USB till you are sure you can send and receive data on this.

You seem to have misunderstood slightly. The 'setup_oscillator' line goes in your code, not in the chip setup.

So the layout needs to be:
Code:

#include <18F45K50.h>
 
#fuses NOWDT, PLLEN, PLL3X, INTRC       
#use delay(clock=48MHz,USB_FULL)
//where is the serial setup for the port connected to COM3?.
 
//then include the USB code

//Then your defines

void main(void)
{
    //now the setups go in the code
    setup_oscillator(OSC_16MHZ|OSC_INTRC|OSC_PLL_ON|OSC_PLL_3X);
    setup_act(ACT_ENABLED | ACT_TUNED_TO_USB);
    //other code, USB etc...

}



You also added 'mode =' to the setup lines. This is the mode _number_ that is defined _by_ the defines. You don't put 'mode =' into the code.

You really need to 'step back' and do some basic programming, like the 'flash an LED' routine, and basic serial IO, _before_ even thinking about trying to get USB 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