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

PIC18F67J94 + cdc + unknown device

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



Joined: 04 May 2015
Posts: 14

View user's profile Send private message

PIC18F67J94 + cdc + unknown device
PostPosted: Tue Nov 07, 2017 12:53 am     Reply with quote

Hello

I have a program with an internal clock and a sosc 32 KHz and everything works, but when i connect to the PC it doesn't see the device.

main.h
Code:


#include <18F67J94.h>
//#include <18F67J50.h>
#device ADC=16


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BROWNOUT_SW              //Brownout controlled by configuration bit in special file register
#FUSES BORV18                   //Brownout reset at 1.8V
#FUSES NOPROTECT                //Code not protected from reading
#FUSES SOSC_LOW                 //Low-power SOSC circuit is selected
#FUSES NOCLOCKOUT               //I/O function on OSC2
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOPLL                    //HW PLL disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES WPFP                     //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPDIS                    //All Flash memory may be erased or written
#FUSES WPEND                    //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES NOWPCFG                  //Configuration Words page is not erase/write-protected
#FUSES T5G_IS_T5G               //Timer 5 Gate is driven by the T5G input
#FUSES CINA_DEFAULT             //C1INA and C3INA are on their default pin locations
#FUSES IOL1WAY                  //Allows only one reconfiguration of peripheral pins
#FUSES MSSP2MSK7                //MSSP2 uses 7 bit Masking mode
#FUSES MSSPMSK7                 //MSSP uses 7 bit Masking mode
#FUSES WDTWIN_25%               //Watchdog Window is 25% of WDT period
#FUSES WDTCLK_FRC               //WDT uses FRC as clock source
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES VREGSLEEP_SW             //Ultra low-power regulator is enabled
#FUSES VBATBOR                  //VBAT BOR Enabled
#FUSES DSBOR                    //BOR enabled in Deep Sleep
#FUSES DS_SW                    //Deep Sleep is controlled by the register bit DSEN
#FUSES DSWDT                    //Deep Sleep Watchdog Timer enabled
#FUSES DSWDTOSC_SOSC            //DSWDT uses SOSC as reference clock

#use delay(internal=8MHz,USB_FULL,ACT=USB)

#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8,stream=Debug)

#bit PLLEN = 0xf64.5 // To solve problem with PLL enable ( found on CCS forums )

#DEFINE SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
#pin_select SCK1=PIN_E7
#pin_select SDI1=PIN_E4
#pin_select SDO1=PIN_E3

#define o_adisRST   PIN_E5

#define  SDA1     PIN_C4
#define  SCL1     PIN_C3
#define  adisonoff     PIN_D1
#define led PIN_G0

//***********
//#define  USB_CON_SENSE_PIN PIN_F7
//#define USB_CABLE_IS_ATTACHED() input(PIN_F7)
#pin_select INT2=PIN_F7
#define  USBINT   PIN_F7
#define USB_CONFIG_VID 0x2405
#define USB_CONFIG_PID 0x000B
#define USB_CONFIG_BUS_POWER 200
#define USB_STRINGS_OVERWRITTEN

//char USB_STRING_DESC_OFFSET[]={0,4,24};

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
      20,  //length of string index
      0x03,  //descriptor type (STRING)
      'a',0,
      'b',0,
      'c',0,
      ' ',0,
      '-',0,
      ' ',0,
      'd',0,
      'e',0,
      'f',0,
   //string 2 - product
      14,  //length of string index
      0x03,  //descriptor type (STRING)
      'a',0,
      'b',0,
      'c',0,
      '3',0,
      '.',0,
      '0',0
};
#include <stdlib.h>
#include <usb_cdc.h>
#include <string.h>



main.c
Code:

void main()
{
   
   setup_wdt( WDT_OFF );
   setup_adc(  ADC_CLOCK_INTERNAL  );
   setup_adc_ports(sAN1|VSS_VDD);   
   setup_rtc(RTC_ENABLE | RTC_CLOCK_SOSC, 0);
   enable_interrupts(INT_RTC); //enable RTC interrupts
   enable_interrupts(INT_EXT2);

   enable_interrupts(GLOBAL); //enable interrupts     

   while(TRUE)
   {
   //usb
      if(F_USB)
      {
          fprintf(debug,"\r\nUSB-Modus");
          USB_MODUS();
      }
      //Sleep
      #use delay(internal=8MHz)
      fprintf(debug,"\r\nSleep Mode\r\n");
      set_tris_a(0x00); //Ausgang
      set_tris_b(0x00);
      set_tris_c(0x00);
      set_tris_d(0x00);
      set_tris_e(0x00);
      set_tris_f(0x80);
      set_tris_g(0x00);

      #use delay(internal=32KHz)
   
      delay_ms(1000);
      setup_spi(SPI_DISABLED);     
      output_low(led);
      output_low(adisonoff); //
      output_high(SDA1);
      output_high(SCL1);
      output_high(PIN_E7);
      output_high(PIN_E4);
      output_high(PIN_E3);
      output_high(PIN_E2);
      output_high(o_adisRST);
   
      output_low(PIN_F3);
      output_high(PIN_F4);
   
      output_low(PIN_C6); //rS232
      output_low(PIN_C7);//RS232
 
      output_low(PIN_A1);
      sleep(SLEEP_FULL||WAKE_FROM_RTCC);
      delay_cycles(1);
   }
}



USB-Modus.c:

Code:

void USB_MODUS(void)
{
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;
   cdc_serial_state_t newState;
   static cdc_serial_state_t lastState;

   usb_init_cs();
     // service low level USB operations.
      usb_task();

      // special debugging routines for this program.
      new_connected=usb_attached();
      new_enumerated=usb_enumerated();
      new_cdc=usb_cdc_connected();


      if (new_connected && !last_connected)
      fprintf(debug,"USB connected, waiting for enumaration...\r\n\n");
      if (!new_connected && last_connected)
      fprintf(debug,"USB disconnected, waiting for connection...\r\n\n");
      if (new_enumerated && !last_enumerated)
      fprintf(debug,"USB enumerated by PC/HOST\r\n\n");
      if (!new_enumerated && last_enumerated)
      fprintf(debug,"USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
      if (new_cdc && !last_cdc)
      fprintf(debug,"Serial program initiated on USB<->UART COM Port\r\n\n");

      last_connected=new_connected;
      last_enumerated=new_enumerated;
      last_cdc=new_cdc;

      // send host DSR state, which is based on button.
         memset(&newState, 0x00, sizeof(newState));

   //newState.bRxCarrier = BUTTON_PRESSED();
   newState.bTxCarrier = newState.bRxCarrier;

   if (memcmp(&newState, &lastState, sizeof(newState)) != 0)
   {
      fprintf(debug,"\r\nNew button state being sent: ");
      //change in state, send it.
      if (usb_cdc_serial_state(newState))
      {
         //state was sent ok, save it in memory so we don't resend it.
         memcpy(&lastState, &newState, sizeof(lastState));
         fprintf(debug,"OK");
      }
      else
      {
         fprintf(debug,"FAIL");
      }
      fprintf(debug,"\r\n");
   }


}


Thanks for your help.
Andmo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2017 2:06 am     Reply with quote

Do you think that the line shown in bold below makes the compiler put in
code to change the oscillator frequency to 32 KHz ? It doesn't do that.
Quote:
#use delay(internal=32KHz)
delay_ms(1000);
setup_spi(SPI_DISABLED);
output_low(led);
output_low(adisonoff); //
output_high(SDA1);
output_high(SCL1);
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Nov 07, 2017 3:54 am     Reply with quote

There is also the old thing. _Simplify_.

Start by simply getting the device to work as a CDC.
Only once you have this basic step working, then try to fiddle.

Now some comments apply to this.

USB _requires_ connection sense.
Repeat _requires_.
You are only allowed not to use it, on a device that is directly powered from the USB connection (so when the USB is powered the device is powered). On any device that keeps running when the USB power goes off, the sense connection is needed to allow it to re-connect from sleep modes etc..
He uses usb_init_cs - the CS here is the connection sense connection. Not going to work.

Test with the standard descriptor before trying to override the strings.

Then he has a 'PLLEN fix, doing nothing.

Then as PCM_Programmer has pointed out he misunderstands the difference between a pre-processor directive, and code. The code to switch clock rates, is 'setup_oscillator'.

In the posted code he has INT_RTC, and INT_EXT2 enabled, but no interrupt handlers shown for these. Result will be a locked up chip.,

Then he is using ADC_CLOCK_INTERNAL. Not important, but this is not recommended at any clock speed above 1Mhz, unless the chip is being put to sleep for the conversion...

He again has the logical 'or' command being shown (||), not the bitwise 'or' the commands require (|).
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