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

one more... QUESTION ABOUT USB-ERROR

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



Joined: 21 Sep 2012
Posts: 10

View user's profile Send private message

one more... QUESTION ABOUT USB-ERROR
PostPosted: Sat Oct 08, 2016 8:32 pm     Reply with quote

I'm trying to work with PIC16F1455 & HID.
I recently started working with the pic16f1455 and I decided to incorporate the example (ex_usb_hid.c).
When i build the example (ex_usb_hid.c) i have not problems to compile,
but if i try run MR.PROTEUS say error of memory out of range.

    [PIC16 LOAD] Program or EEPROM data has invalid address [180004] for this device [U2]
    [PIC16 LOAD] Program or EEPROM data has invalid address [180005] for this device [U2]
    [PIC16 LOAD] Program or EEPROM data has invalid address [180006] for this device [U2]
    Internal Exception: access violation in module 'PIC16EX.DLL' [0004A347].

(PROTEUS 8.5 SP0)

in order to customize and the desire to save memory, I change this:


BEFORE

Code:
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#if __USB_PIC_PERIF__
 #if defined(__PCM__)
  #include <pic16f_usb.h>   //Microchip PIC16Fxxxx hardware layer for usb.c
 #elif defined(__PCH__)
  #include <pic18_usb.h>   //Microchip PIC18Fxx5x hardware layer for usb.c
 #elif defined(__PCD__)
  #include <pic24_usb.h>   //Microchip PIC24 hardware layer for usb.c
 #endif
#else
 #include <usbn960x.h>   //National 960x hardware layer for usb.c
#endif
#include <usb_desc_hid.h>   //USB Configuration and Device descriptors for this UBS device
#include <usb.c>        //handles usb setup tokens and get descriptor reports



AFTER

Code:
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
  #include <16F1455.h>          //ccs lib. for PIC16F1455
  #include <pic16f_usb.h>       //Microchip PIC16Fxxxx hardware layer for usb.c


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


all the rest of the code is the same, now the problem starts when I compile.

Quote:
*** Error 23 "C:\Program Files\PICC\Devices\16F1455.h" Line 11(9,19): Can not set this option this far into the code
*** Error 28 "C:\Program Files\PICC\Devices\16F1455.h" Line 501(34,35): Expecting an identifier Bad SFR name
*** Error 110 "C:\Program Files\PICC\Devices\16F1455.h" Line 502(5,6): Expecting a .
*** Error 43 "C:\Program Files\PICC\Devices\16F1455.h" Line 502(13,14): Expecting a declaration
*** Error 28 "C:\Program Files\PICC\Devices\16F1455.h" Line 502(34,35): Expecting an identifier Bad SFR name
*** Error 48 "C:\Program Files\PICC\Devices\16F1455.h" Line 502(34,35): Expecting a (
*** Error 119 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 64(8,63): Unknown PIC device, USB not supported in this library.
*** Error 119 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 121(13,90): You are trying to allocate more memory for endpoints than the PIC can handle
*** Error 119 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 126(8,69): You are trying to use an invalid endpoint for this hardware!
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 238(2,6): Undefined identifier
*** Error 48 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 238(7,12): Expecting a (
*** Error 43 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 238(33,35): Expecting a declaration
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 252(21,32): Undefined identifier USB_NUM_UEP
*** Error 43 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 252(33,34): Expecting a declaration
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 398(17,30): Undefined identifier PIN_USB_DPLUS
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 399(17,31): Undefined identifier PIN_USB_DMINUS
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 764(21,32): Undefined identifier USB_NUM_UEP
*** Error 76 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 764(38,39): Expect ;
*** Error 12 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 817(16,27): Undefined identifier USB_NUM_UEP
*** Error 76 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 817(32,33): Expect ;
*** Error 108 "C:\Program Files\PICC\Drivers\pic16f_usb.c" Line 856(20,28): Invalid parameters to built in function :: Not a valid interrupt
21 Errors, 0 Warnings.



In my opinion i try USB_HID because we do not need drivers.
But now i do not care if someone have a example using USB_BULK, USB_CDC or USB_HID. Anyway, USB i want.

Can someone give me an opinion about my tiny problem?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 08, 2016 9:23 pm     Reply with quote

That's not the correct file to specify the PIC. The PIC is specified in
Ex_usb_common.h. Look in that file, at the section for the 16F1459.
Your PIC is most similar to that PIC. So modify that section.

Un-comment the line for the 161459. Or alternatively, create a new
#define for your PIC.
Quote:

////// Begin User Configuration

//#define USB_HW_CCS_PIC18F4550 //CCS PIC18F4550 USB Development kit
//#define USB_HW_CCS_PIC18F45K50 //CCS PIC18F45K50 USB Development kit
//#define USB_HW_CCS_E3 //CCS E3 Mini development kit. 18F14K50 with 12Mhz crystal.
#define USB_HW_CCS_16F1459 //CCS Rapid USB devleopment kit. 16F1459 with no oscillator
//#define USB_HW_CCS_PIC24F //CCS 24FJ256GB206 USB Development kit
//#define USB_HW_CCS_PIC33EP //CCS PIC24 USB Development kit, PIC replaced with a 33EP256MU806
//

Then you will have to modify a few lines in the 16F1459 section to get it
to compile with a 16F1455. Suggestions are shown in bold below.
These are only suggestions.
Quote:

#if defined(USB_HW_CCS_16F1459)
//#include <16F1459.h>
#include <16F1455.h>
#use delay(int=8MHz, clock=48MHz, USB_FULL, act=USB)

#fuses MCLR
#fuses PUT
#fuses NOWDT

//leds are ordered left to right
#define LED_DIR1 PIN_C2 // *** was PIN_A5
#define LED_DIR2 PIN_C3 // *** was PIN_C6
#define LED_ON(x) delay_cycles(1)
#define LED_OFF(x) delay_cycles(1)
#define LEDS_OFF() output_low(LED_DIR1); output_low(LED_DIR2)
#define LEDS_GREEN() LEDS_OFF(); output_high(LED_DIR1)
#define LEDS_RED() LEDS_OFF(); output_high(LED_DIR2)
#define LEDS_TOGGLE() output_toggle(LED_DIR1); output_toggle(LED_DIR2)

#define BUTTON_PRESSED() !input(PIN_C1)

#define HW_ADC_CONFIG ADC_CLOCK_INTERNAL
#define HW_ADC_CHANNEL 3 // *** was 11 //PIN_B5
#define HW_ADC_PORTS sAN3 // *** was sAN11

#define HW_INIT() setup_adc_ports(HW_ADC_PORTS); setup_comparator(NC_NC_NC_NC)

#define __NO_UART__

//#define UART_IS_ICD

#if defined(UART_IS_ICD)
#warning Can't use button and ICSP streaming because they share the same pin!
#define UART_ICD_SETTINGS xmit=PIN_C0, rcv=PIN_C1, baud=57600
#endif
#endif


If you do all this, then it will compile. Make sure MPLAB is set for Release
mode. You will get the usual warnings "Interrupts disabled during call to
prevent re-entrancy". Just ignore them.

I don't guarantee the compiled program will work. I am only helping you
to get it to compile.
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Sat Oct 08, 2016 10:57 pm     Reply with quote

look at the top of the forum. no PROTEUS questions, it will cause you more work than it saves you. get real hardware.
temtronic



Joined: 01 Jul 2010
Posts: 9169
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 09, 2016 5:30 am     Reply with quote

also while Proteus will not complain about...
#define HW_ADC_CONFIG ADC_CLOCK_INTERNAL

if this code does use the internal adc clock

then REAL hardware will NOT function properly...


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Sun Oct 09, 2016 1:05 pm     Reply with quote

and as comment, the changes won't save any memory.

The stuff you are removing, is _preprocessor_ operations, which mean they are all done before the code is compiled. It rejects all the stuff it isn't using.
chico_pic



Joined: 21 Sep 2012
Posts: 10

View user's profile Send private message

PostPosted: Sat Oct 15, 2016 9:21 pm     Reply with quote

I try using create project from CCS compiler.

Now when i run in Proteus my computer can detect it but can not install the driver for my device.

Can someone try with my code??
Maybe the error is my PC.
Code:

#include <little_hid.h>

//#include <ios.h>

/* TODO: Use usb_put_packet() to transmit data to USB HID,
using USB_HID_ENDPONT for the endpoint and the payload size
needs to match USB_CONFIG_HID_TX_SIZE. Use usb_get_packet()
to read incoming data, using USB_HID_ENDPOINT for the
endpoint. usb_enumerated() can be used to see if connected to
a host and ready to communicate. */

void main()
{
   setup_adc_ports(sAN4);
   setup_adc(ADC_CLOCK_INTERNAL);
   usb_init();

   while(TRUE)
   {

      //Example blinking LED program
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);

      //TODO: User Code
   }

}

little_hid.h
Code:

#include <16F1455.h>
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer

#use delay(internal=48MHz,USB_FULL,ACT=USB)
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8,stream=PC_COMM)

#define LED PIN_C2
#define DELAY 500

#define USB_CABLE_IS_ATTACHED()  input(PIN_C1)
#define USB_CONFIG_VID 0x0461
#define USB_CONFIG_PID 0x0033
#define USB_CONFIG_BUS_POWER 500
#define USB_STRINGS_OVERWRITTEN

char USB_STRING_DESC_OFFSET[]={0,4,32};

char const USB_STRING_DESC[]={
   //string 0 - language
      4,  //length of string index
      0x03,  //descriptor type (STRING)
      0x09,0x04,  //Microsoft Defined for US-English
   //string 1 - manufacturer
      28,  //length of string index
      0x03,  //descriptor type (STRING)
      'A',0,
      'B',0,
      'C',0,
      'D',0,
      '_',0,
      'E',0,
      'F',0,
      'G',0,
      'H',0,
      'J',0,
      'K',0,
      'L',0,
      'M',0,
   //string 2 - product
      22,  //length of string index
      0x03,  //descriptor type (STRING)
      'L',0,
      'I',0,
      'T',0,
      'T',0,
      'L',0,
      'E',0,
      '_',0,
      'H',0,
      'I',0,
      'D',0
};

#define USB_CONFIG_HID_TX_SIZE 10
#define USB_CONFIG_HID_RX_SIZE 10
#include <pic16f_usb.h>
#include <usb_desc_hid.h>
#include <usb.c>

Just need C1 as detector POWER USB to run.
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Sun Oct 16, 2016 1:16 am     Reply with quote

Read the forum header about Proteus...

However:

setup_adc(ADC_CLOCK_INTERNAL);

Still wrong. This clock is _not_ what you need to use.

Won't affect your USB though.

Big problem is you are not actually handling the USB tasks:
Code:

void main()
{
   setup_adc_ports(sAN4);
   setup_adc(ADC_CLOCK_DIV_64);
   usb_init_cs();
   //You should be using the CS version with the USB detect
   //specified
   enable_interrupts(GLOBAL);
   //USB _requires_ the interrupts to be enabled, unless you specify
   //to use 'polling'. If you use polling then usb_task _must_ be called
   //at very fast intervals (no more than perhaps 10mSec)
   //without polling, the USB task still needs to be called, but a couple
   //of times a second is acceptable (it handles things like making
   //the connection!.....).

   while(TRUE)
   {
      usb_task();
      //even with the interrupt enabled, The USB task _[u]must[/u]_
      //still be called at intervals. It is what handles the 'house keeping'

      //Example blinking LED program
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);

      //TODO: User Code
   }
}


You also have a problem with your descriptor. The HID device descriptor specifies that a serial number is used. So the descriptor needs to include one.
Also the device descriptor specifies that a vendor name is also included.
It's much easier now to use the modern way of creating the unicode descriptors. Look at how they are built in the include file now. Much easier to customise...
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