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

Need USB help , pcm 3.150, pic16c745

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







Need USB help , pcm 3.150, pic16c745
PostPosted: Tue Apr 08, 2003 9:59 am     Reply with quote

hi there !
i've problems with the new pcm compiler 3.150 which provides the usb for pic16c7x5.

there is one example program in the picc folder for an hid device "ex_usb_hid.c", i haven't found the example "ex_usb.h" which is listed on the homepage and in the description of usb.
i tried to program the pic but after connecting my hardware with the pc there was the error message "unknown usb feature, probably not functionally"
i think there must be something wrong with the descriptors, they aren't includet in the program !!

here is the program i tried !!
can anyone help me ??? please
thx a lot


#define USB_PIC16C745 1 //set to 1 to use a PIC16c745 USB Peripheral
//set to 0 to use a National USBN960x peripheral

#if USB_PIC16C745 //use the PIC16C7x5 peripheral
#include <16C745.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=24000000)

#else //use the National USBN960x peripheral
#if defined(__PCM__)
#include <16F877.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#endif
#use delay(clock=20000000)

#endif //endif check to see which peripheral to use

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#DEFINE LED_1 PIN_B5
#DEFINE LED_2 PIN_B4
#DEFINE LED_3 PIN_B3
#DEFINE BUTTON PIN_A4

//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE

//Set this to FALSE if you only want to test enumeration. Some USB test programs,
//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE 1 //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //if you change this, be sure to change the hid descriptor

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE 1 //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 2 //if you change this, be sure to change the hid descriptor

#if USB_PIC16C745
#include <pic_usb.h> //Microchip PIC16C745 hardware layer for usb.c
#else
#include <usbn960x.c> //National 960x hardware layer for usb.c
#endif

#include <usb.c> //handles usb setup tokens and get descriptor reports

void main() {
int8 out_data[USB_EP1_TX_SIZE];
int8 in_data[USB_EP1_RX_SIZE];

#ifdef __PCH__
printf("\r\n\r\nPCH: v");
printf(__PCH__);
#else
printf("\r\n\r\nPCM: v");
printf(__PCM__);
#endif

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(RA0_RA1_RA3_ANALOG);
set_adc_channel(1);

usb_init();

#if !(USB_PIC16C745)
printf("\r\nUSBN: 0x\%X\r\n", usbn_get_version());
output_low(LED_1);
output_low(LED_2);
output_low(LED_3);
delay_ms(1000);
output_high(LED_1);
output_high(LED_2);
#else
printf("\r\n");
#ENDIF


printf("\r\n\r\nWaiting for enumeration...");

while (TRUE) {
usb_wait_for_enumeration();
printf("\r\n\r\n***Enumerated***\r\n");
while(usb_enumerated()) {
#IF USB_RUN_WHEN_CONFIGURED
if (usb_kbhit(1)) {
usb_gets(1, in_data, USB_EP1_RX_SIZE);
printf("\r\n--> Received 2 bytes: 0x\%X 0x\%X",in_data[0],in_data[1]);
if (in_data[0]) {output_low(LED_1);} else {output_high(LED_1);}
if (in_data[1]) {output_low(LED_2);} else {output_high(LED_2);}
}
out_data[0]=read_adc();
out_data[1]=!input(BUTTON);
if (usb_put_packet(1, out_data, USB_EP1_TX_SIZE, TOGGLE)) {
printf("\r\n<-- Sending 2 bytes: 0x\%X 0x\%X", out_data[0], out_data[1]);
}
delay_ms(500);
#ENDIF
}
printf("\r\n\r\nDevice Un-configured.r\n");
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13500
Andy Drummond
Guest







USB done the EASY way!!
PostPosted: Wed Apr 09, 2003 8:06 am     Reply with quote

Hi there. I don't know if this is helpful, but I wanted to use USB with a PIC a while back and failed dismally to work out what to do. I found that FTDI (Future Technology Devices Inc ?) make two parts, the FT245BM and the FT232??. Little 32-pin LQFP part, very low cost. The -245 is an 8-bit FIFO with RxF, TxE, Wr and Rd lines, the -232 is a full RS232 I/O part (except for voltage levels). And FTDI supply (free) all the PC software, drivers, examples, etc. It made my life so much easier that I am now a converted FTDI enthusiast. When I put my PCB together with this part it was all running the same day; so easy.

So if that is useful, you're welcome.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13538
diego_huelva@hotmail.com
Guest







PostPosted: Sat Jan 03, 2004 12:26 pm     Reply with quote

HI Andy Drummond! These code that you post is a modification of "ex_usb_hid.c" example. ¿? I have you same problem! With the PIC16C765, it works well, but not with the PIC16C745. If you find the solution, write me to diego_huelva@hotmail.com, please!!! Sorry for my english, I am spanish.
hillcraft



Joined: 22 Sep 2003
Posts: 101
Location: Cape Town (South africa)

View user's profile Send private message Send e-mail Visit poster's website

16C745 USB
PostPosted: Sun Jan 04, 2004 2:16 am     Reply with quote

I use the 745 USB with great success. The best way to get going is to make a HID device like a mouse or a joystick. The reason for this is that Windows will automatically build the device driver for you. You must also do a hell of a lot of readind about the manner in which USB endpoints are defined and how enumeration is done.

There is no great difference betwen the 745 and the 765. I would love to know why Microchip does not provide a Flash USB chip.
diego_huelva
Guest







PostPosted: Wed Jan 07, 2004 11:56 am     Reply with quote

Hi hillcraft!
Can you post a code example that works with 16C745? Please!!!
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