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-HID PIC24FJ256GB106

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



Joined: 06 Mar 2009
Posts: 21

View user's profile Send private message Send e-mail

USB-HID PIC24FJ256GB106
PostPosted: Fri Oct 29, 2010 4:10 am     Reply with quote

Hi boys,
I need help becuase I'm start to working with PIC24. I need connect my pic with USB in HID mode.
I have 20 Mhz External oscillator, VUSB in connect to 330 nF capacitor to GND, D+ e D- is correctly connect to miniUSB connector and my micro is PIC24FJ256GB106. I have also a USB pin sense that is place to PIN_B0.

The problem is that microncontroller Never connect to USB. Windows don't show Pop-Up, don'play sound (USB inserted).Everything do nothing.
I think that I wrong some configuration on fuses/delays.
I start to working yesterday with this device and I need more explanation. I don't find enough information about.

I have problem also with USART, and I2C. Someone can help me?
I have post the circuit on [url] http://www.megaupload.com/?d=SUM2VYPN.

this is my main code:

Code:



#include <24FJ256GB106.h>


#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES DEBUG                  //No Debug mode for ICD
#FUSES ICSP2                    //ICD uses PGC1/PGD1 pins
//#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
//#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
//#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO                     //Internal External Switch Over mode enabled
//#FUSES PR                       //Primary Oscillator
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO                  //OSC2 is clock output
//#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES IOL1WAY                  //Allows only one reconfiguration of peripheral pins
#fuses HS,PR_PLL,PLL5    // Crystal HS, 4xPLL
//#fuses OSC_CRYSTAL
//#FUSES NOPUT                   
//#FUSES NOMCLR
//#FUSES WPEND_LOW             
//#FUSES NOWPCFG               
//#FUSES NOWPDIS               
//#FUSES WPFP3                 
//#FUSES WPFP4                 
////#FUSES PLL6                   //Divide By 12(48MHz oscillator input)
//#FUSES DISUVREG             
//#FUSES WPFP5                 
//#FUSES WPFP6                 
//#FUSES WPFP0                 
//#FUSES WPFP1                 
//#FUSES WPFP2                 
//#FUSES WPFP7                 
//#FUSES WPFP8                 
//#FUSES RESERVED                 
//#use delay(clock=20000000)
#use delay (clock=20000000)

#define __USB_PIC_PERIF__ 1
#define USB_CON_SENSE_PIN PIN_B0
#define USB_CONFIG_HID_TX_SIZE   64
#define USB_CONFIG_HID_RX_SIZE   64
#define USB_CONFIG_HID_TX_POLL 255
#define USB_CONFIG_HID_RX_POLL 255

#include <pic24_usb.h>   
#include <usb_desc_hid.h>   
#include <usb.c>

#define LED1 PIN_D6      // led open port
#define LED2 PIN_G6      // led rx RS485
#define LED3 PIN_G7      // led tx RS485   
#define LED4 PIN_G8      // led STATUS
#define LED5 PIN_G9      // led rx USB


int8 start=0;
int8 buffer[64]={0};

int8 msg_ready_485=1;
int8 index_485=0;
int8 start_485=0;
int8 checksum_485=0;
int8 dato_485=0;


int8 dato;
int8 msg_ready=0;
int8 dataeb;
int8 index_radio=0;
int8 index_usb=0;
int8 index_usb1=0;
int8 lunghezza=0;
int8 buff_radio[64]={0};
int8 buff_485[64]={0};

int8 in_data[64]={0};    // Set array to zero
int8 out_data[64]={0};  // Set array to zero
int8 t_led3=0;
int8 t_led5=0;    // tempo accensione LED5
int8 t_led6=0;    // tempo accensione LED6

int16 timeout=0;
INT8 i=0,z=0,g=0;
int8 loli=0;
int8 checksum=0;
int8 chksum=0;
int8 chksum2=0;

int8 Flag1 = 0x00;
#bit ready_usb = Flag1.0       // flag 5 sec   SETTATO a 1 all'avvio !!!
#bit ready_485= Flag1.1       // flag lettura sonde drive
#bit pippo = Flag1.2     // flag flash led4
#bit ready2_485 = Flag1.3       // flag 5 sec
#bit toni  = Flag1.4      // flag uscita aux attiva

/////////////////////////////////////////////////////////////////////////

// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.

/////////////////////////////////////////////////////////////////////////
void usb_debug_task(void)
{

   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();

//   if (new_enumerated)
//      LED_ON(LED1);
//   else
//      LED_OFF(LED1);
//

   last_connected=new_connected;
   last_enumerated=new_enumerated;
}

void main(void)
{
int8 l=0,i=0;
int8 lunghezza=0;
int8 lunghezza2=0;
int32 cont=0;

////setup_wdt(WDT_TIMES_128);
//set_tris_b(0b00011110);      // porta utilizzata per i vari tasti.
//set_tris_c(0b10000000);      // tutto out: EEPROM I2C,IR_OUT,  BUZZER, LED,485
//set_tris_a(0b10000000);      // tutto out: EEPROM I2C,IR_OUT,  BUZZER, LED,485
set_tris_d(0x0000);      // tutto out: EEPROM I2C,IR_OUT,  BUZZER, LED,485
set_tris_G(0x0000);      // tutto out: EEPROM I2C,IR_OUT,  BUZZER, LED,485
//set_tris_f(0x0010);      // tutto out: EEPROM I2C,IR_OUT,  BUZZER, LED,485


output_high(LED1);
delay_ms(500);
output_high(LED2);
delay_ms(500);
output_high(LED3);
delay_ms(500);
output_high(LED4);
delay_ms(500);
output_high(LED5);
delay_ms(500);

output_low(LED1);
delay_ms(500);
output_low(LED2);
delay_ms(500);
output_low(LED3);
delay_ms(500);
output_low(LED4);
delay_ms(500);
output_low(LED5);
delay_ms(500);

usb_init();
usb_task();
usb_debug_task();

while (TRUE)
   {
      usb_task();
        usb_debug_task(); 

      if (usb_enumerated())
         {

       if(usb_kbhit(1))
         {

            lunghezza=usb_get_packet(1,in_data,64);
         lunghezza++;   // used to debug breakpoint
      
         output_high(LED4);
         delay_ms(500);
         output_low(LED4);
         lunghezza++;   // used to debug breakpoint
      }   

       }
     }
 
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 29, 2010 11:07 am     Reply with quote

The fuses seem basically correct.

As a minor point, the correct #use delay statement would set clock=32M, not 20M. So UART frequencies and delays can't be right, but USB operation shouldn't be affected.

Unfortunately, I can't decode the schematic details, because it's too low resolution.
Ln_mark7930



Joined: 06 Mar 2009
Posts: 21

View user's profile Send private message Send e-mail

Do you want original schematics?
PostPosted: Fri Oct 29, 2010 11:36 am     Reply with quote

FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 29, 2010 2:35 pm     Reply with quote

Quote:
The number inserted inside #use delay(clock=xxxxxx) mean witch primary oscillator (external oscillator) work at xxxxxx frequency

No, just refer to the manual:
Quote:
clock=speed...This specified the clock the CPU runs at.

It's 32 MHz (or divided down to 16, 8 ...) with PIC24FxxGB.

You can however use a syntax like this
Quote:
#use delay(oscillator=10Mhz, clock=40Mhz)

It will correctly setup the fuses in some cases. Please don't ask me wheter or not in a specific case...

By the way, according to your schematic, you're using an external 20 MHz crystal, not an oscillator. So it's correct to set #fuse HS, for the latter use EC.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Oct 29, 2010 2:53 pm     Reply with quote

I found two flaws in your schematic related to the USB circuit.
- different from PIC18, VUSB has to be connected to a 3.3V supply
- VBUS is intended to be directly wired to the USB connector. I doubt, if it accepts a 100 k series resistor, but I didn't further check for this point.

For a detailed description of PIC24FxxGB USB interface and suggested operation, consult the respective section 27 of the PIC24F family reference manual rather than the datasheet.
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