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

USB support on PIC24EP devices

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



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

USB support on PIC24EP devices
PostPosted: Fri Feb 03, 2012 2:36 am     Reply with quote

Hi to all,

Has anyone been able to test USB on PIC24EP devices (24EP512GU810 for ex). This device is supported by the latest compiler version, however USB is not.

Thank you
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 3:27 am     Reply with quote

What's the specific USB support problem with these devices? Is the USB hardware different from 24FJxxxGB types?
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 5:57 am     Reply with quote

I was trying to run the ex_usb_serial example provided by CCS.

I have added a new definition of a board (PIC24E starter kit) as follows:

Code:

#include <24EP512GU810.h>
   #include "C:\24EP512GU810_registers.h"

   #FUSES PR_PLL                   //Primary Oscillator with PLL
   #FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
   #FUSES NOGSSK                   //General Segment Key bits, use if using either NOWRT or NOPROTECT fuses
   #FUSES CKSNOFSM                 //Clock Switching is enabled, fail Safe clock monitor is disabled
   #FUSES ALTI2C1                  //I2C1 mapped to ASDA1/ASCL1 pins
   #FUSES NOJTAG                   //JTAG disabled
   #FUSES NOWDT
   
   #device ADC=8
   
   #use delay(clock=120M)
   
   #pin_select U1TX = PIN_D5
   #pin_select U1RX = PIN_D4
   
   #define LED1 PIN_D0
   #define LED2 PIN_D1
   #define LED3 PIN_D2
   
   #define LED_ON(x) output_high(x)
   #define LED_OFF(x) output_low(x)
   #define BUTTON_PRESSED() !input(PIN_D6)
   #define BUTTON2_PRESSED() !input(PIN_D7)

   #define HW_ADC_PORTS    sAN5
   #define HW_ADC_CHANNEL  5
   #define HW_ADC_CONFIG   ADC_CLOCK_INTERNAL | ADC_TAD_MUL_31


And the following code to the beginning of the main function (as written in the MCP C33 USB code):
Code:

MCU_ANSELA = 0x0000;
      MCU_ANSELB = 0x0000;
      MCU_ANSELC = 0x0000;
      MCU_ANSELD = 0x0000;
      MCU_ANSELE = 0x0000;
      MCU_ANSELG = 0x0000;
     
      MCU_RPINR19 = 0;
      MCU_RPINR19 = 0x64;
      MCU_RPOR9.RP101R = 0x3;
     
      // Configure the device PLL to obtain 60 MIPS operation. The crystal
       // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by
       // 2. This results in Fosc of 120MHz. The CPU clock frequency is
       // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then
       // configure the auxilliary PLL to provide 48MHz needed for USB
       // Operation.
     
      MCU_PLLFBD = 38;            /* M  = 60   */
      MCU_CLKDIV.PLLPOST = 0;      /* N1 = 2   */
      MCU_CLKDIV.PLLPRE = 0;      /* N2 = 2   */
      MCU_OSCTUN = 0;         
     
      LED_ON(LED1);
     
      /*   Initiate Clock Switch to Primary
        *   Oscillator with PLL (NOSC= 0x3)*/
         //__builtin_write_OSCCONH(0x03);     
         //__builtin_write_OSCCONL(0x01);
      #asm
         //Place the New Oscillator Selection in W0
         MOV 0x03,w0
         //OSCCONH (high byte) Unlock Sequence
         MOV MCU_OSCCONH, w1
         MOV 0x78, w2
         MOV 0x9A, w3
         MOV.B w2, [w1] // Write 0x78
         MOV.B w3, [w1] // Write 0x9A
         //Set New Oscillator Selection
         MOV.B w0, [w1]
         
         //Place 0x01 in W0 for setting clock switch enabled bit
         MOV 0x01, w0
         //OSCCONL (low byte) Unlock Sequence
         MOV MCU_OSCCONL, w1
         MOV 0x46, w2
         MOV 0x57, w3
         MOV.B w2, [w1] //Write 0x46
         MOV.B w3, [w1] //Write 0x57
         //Enable Clock Switch
         MOV.B w0, [w1] //Request Clock Switching by Setting OSWEN bit
         wait:
            btsc MCU_OSCCONL, 0  //#OSWEN
            bra wait
      #endasm
     
      LED_ON(LED2);
     
      while (MCU_OSCCON.COSC != 0x3);       
     
      LED_ON(LED3);
       // Configuring the auxiliary PLL, since the primary
       // oscillator provides the source clock to the auxiliary
       // PLL, the auxiliary oscillator is disabled. Note that
       // the AUX PLL is enabled. The input 8MHz clock is divided
       // by 2, multiplied by 24 and then divided by 2. Wait till
       // the AUX PLL locks.
   
       MCU_ACLKCON3 = 0x24C1;   
       MCU_ACLKDIV3 = 0x7;
       
       MCU_ACLKCON3.ENAPLL = 1;
       while(MCU_ACLKCON3.APLLCK != 1);


The clock configuration is OK, 60MIPS. I'm still testing IO peripherals, but seems to be working till now; except for USB.

Thanks
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