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 CCS Technical Support

usb module with dspic33f

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



Joined: 27 Apr 2013
Posts: 55

View user's profile Send private message

usb module with dspic33f
PostPosted: Sat Aug 17, 2013 6:59 pm     Reply with quote

I am trying to use a usb module but my problem is that there is not resources for usb for dspic33f series.

Code:



#define LED1 PIN_B7
#define LED2 PIN_B6
#define LED3 PIN_B5

//Transmit and Receive Packet Size
#define USB_CONFIG_HID_TX_SIZE 16
#define USB_CONFIG_HID_RX_SIZE 16

/*******VENDOR ID AND PRODUCT ID********/
#define USB_CONFIG_PID 1        //Chnage Vendor Id and Product Id
#define USB_CONFIG_VID 4660        //So that they will work with my Application
/***************************************/

//#include<pic18_usb.h>
//#include<usb_desc_hid.h>
//#include<usb.c>
  #include <pic24_usb.h>
#include <usb_desc_hid.h>
//#include <usb_desc_scope.h>   //USB Configuration and Device descriptors for this UBS device
#include <usb.c>        //handles usb setup tokens and get descriptor reports


//Macro Definition for LED ON and OFF
#define LED_ON(x) output_low(x)
#define LED_OFF(x) output_high(x)

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);

       if (new_connected && !last_connected)
          printf("\r\n\nUSB connected, waiting for enumaration...");
       if (!new_connected && last_connected)
          printf("\r\n\nUSB disconnected, waiting for connection...");
       if (new_enumerated && !last_enumerated)
        printf("\r\n\nUSB enumerated by PC/HOST");
       if (!new_enumerated && last_enumerated)
        printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

       last_connected=new_connected;
       last_enumerated=new_enumerated;
}





void main(void)
{
   
    unsigned char in_data[16];
    unsigned int i;
    set_tris_b(0x00);    //Port-B as Output Port
    set_tris_c(0x10);
    output_b(0x00);
    LED_OFF(LED1);
    LED_OFF(LED2);
    LED_OFF(LED3);
    lcd_init();        //Initialize the LCD Module
    lcd_gotoxy(3,1);
    lcd_putc("PIC18F4550");
    Delay_ms(1000);
    lcd_gotoxy(3,2);
    lcd_putc("USB EXAMPLE!");
   
    printf("\r\n\nUSB Test Program--->Written in CCS PIC-C");
    printf("\r\nEMBEDDED LABORATORY\r\n");
    usb_init_cs();
    Delay_ms(1000);
    lcd_putc("\fRECEIVED DATA:-");
    Delay_ms(1);
    while(1)
    {
        usb_task();
        usb_debug_task();
        if(usb_enumerated())
        {
            if(usb_kbhit(1))
            {
                lcd_gotoxy(1,2);
                lcd_putc("                ");
                usb_get_packet(1,in_data,16);
                printf("\r\nReceived Data: ");
                for(i=0;i<16;i++)
                {
                    printf("%c",in_data[i]);   
                    //Send the Recevied Data to Serial Port
                    lcd_gotoxy(1+i,2);
                    lcd_putc(in_data[i]);
                }
                //Now Clear the in_data array
                for(i=0;i<16;i++)
                {
                    in_data[i] = '\0';    //Null Character
                }

            }
           }       
    }
}           





usb module with dspic33f
PostPosted: Sat Aug 17, 2013 6:57 pm Reply with quote Edit/Delete this post Delete this post
I am trying to use a usb module but my problem is that there is not resources for usb for dspic33f series.

Code:


#define LED1 PIN_B7
#define LED2 PIN_B6
#define LED3 PIN_B5

//Transmit and Receive Packet Size
#define USB_CONFIG_HID_TX_SIZE 16
#define USB_CONFIG_HID_RX_SIZE 16

/*******VENDOR ID AND PRODUCT ID********/
#define USB_CONFIG_PID 1 //Chnage Vendor Id and Product Id
#define USB_CONFIG_VID 4660 //So that they will work with my Application
/***************************************/

//#include<pic18_usb.h>
//#include<usb_desc_hid.h>
//#include<usb.c>
#include <pic24_usb.h>
#include <usb_desc_hid.h>
//#include <usb_desc_scope.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports


//Macro Definition for LED ON and OFF
#define LED_ON(x) output_low(x)
#define LED_OFF(x) output_high(x)

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);

if (new_connected && !last_connected)
printf("\r\n\nUSB connected, waiting for enumaration...");
if (!new_connected && last_connected)
printf("\r\n\nUSB disconnected, waiting for connection...");
if (new_enumerated && !last_enumerated)
printf("\r\n\nUSB enumerated by PC/HOST");
if (!new_enumerated && last_enumerated)
printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

last_connected=new_connected;
last_enumerated=new_enumerated;
}





void main(void)
{

unsigned char in_data[16];
unsigned int i;
set_tris_b(0x00); //Port-B as Output Port
set_tris_c(0x10);
output_b(0x00);
LED_OFF(LED1);
LED_OFF(LED2);
LED_OFF(LED3);
lcd_init(); //Initialize the LCD Module
lcd_gotoxy(3,1);
lcd_putc("PIC18F4550");
Delay_ms(1000);
lcd_gotoxy(3,2);
lcd_putc("USB EXAMPLE!");

printf("\r\n\nUSB Test Program--->Written in CCS PIC-C");
printf("\r\nEMBEDDED LABORATORY\r\n");
usb_init_cs();
Delay_ms(1000);
lcd_putc("\fRECEIVED DATA:-");
Delay_ms(1);
while(1)
{
usb_task();
usb_debug_task();
if(usb_enumerated())
{
if(usb_kbhit(1))
{
lcd_gotoxy(1,2);
lcd_putc(" ");
usb_get_packet(1,in_data,16);
printf("\r\nReceived Data: ");
for(i=0;i<16;i++)
{
printf("%c",in_data[i]);
//Send the Recevied Data to Serial Port
lcd_gotoxy(1+i,2);
lcd_putc(in_data[i]);
}
//Now Clear the in_data array
for(i=0;i<16;i++)
{
in_data[i] = '\0'; //Null Character
}

}
}
}
}





Is anyone who can help me?
Ttelmah



Joined: 11 Mar 2010
Posts: 19561

View user's profile Send private message

PostPosted: Sun Aug 18, 2013 4:37 am     Reply with quote

What chip are you actually trying to use?.
What compiler version?.
Only four of the DSPic's have a USB module. The 33EP256/512xx810/814. The module is the same unit as the PIC24EP.
On these chips the #define __PIC_24_USB_H__ is defined by the compiler, and the code does compile for these, but only with the latest compilers.

Best Wishes
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