:(

Originally Posted by
Darrel Taylor
The USB routines are not setup to handle a resume.
So your best bet it probably to connect the +5V from the USB cable to one of the INT pins with a pull-down resistor.
When the cable gets plugged in, it will generate an interrupt, at which point you would execute an @ RESET to reset the processor and initialize the USB again.
HTH
OK, so I made changes to my code per your suggestions (see partial code below) including an IF Plugged =1 test in the Main loop to pole for USB connection and go to my USB servicing procedure when connected. I didn't do anything to get SLEEP mode yet because I want to make sure the interrupts are working first in this code.
This code compiles, but creates a single error during assembly that says
"Error[101]c:\PathToAsmfile.asm 1132:ERROR:(INT_ENABLE priority state not found)". So I can't get it to run yet with this error.
I'm not sure what this error is telling me...the required statement for @ INT_ENABLE INT2_INT is in the code. Does it also require an INT_ENABLE USB_HANDLER statement for the USB interrupt??
Code:
Include "Modedefs.Bas"
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
DEFINE OSC 48
;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
' Initialize Hardware
' ===================
Spare_1 VAR PORTB.7 ' PGD for ICSP & Spare I/O for normal ops
Spare_2 VAR PORTB.6 ' PGC for ICSP & Spare I/O for normal ops
'Set registers
TRISA = 0 ' PORTA all outputs for LCD use
TRISB =%00011000 ' RB4 & RB3 set as RTC Alarm1 & Alarm2 inputs
TRISC = 0
TRISD = 0
TRISE = 0
'------------SETUP FOR USING DS1337 Real Time Clock (RTC)---------------
'***********************************************************************
' Setup Hardware for uart
' =======================
DEFINE HSER_BAUD 115200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1
' Aliased Variables for CLock
' ===========================
Alarm1 VAR PORTB.4 ' Alarm1 input from DS1337 INTA
Alarm2 VAR PORTB.3 ' Alarm2 input from DS1337 INTB
SCL VAR PORTB.1 ' I2C clock pin
SDA VAR PORTB.0 ' I2C data pin
RTC CON %11010000 ' RTC device write address(byte addressing)
' This is a list of allowable clock contrl settings, one which must be
' setup in the SetTimeAndDate subroutine as intended.
'contrl CON %00000011 ' Starts the oscillator, sets the SQW/OUT
' to 1 Hz, enables INTA interrupt from A1F
' or from A2F. WORKS as intended!!
'contrl CON %00000111 ' Starts oscillator, enables INTA interrupt
' from A1F or INTB from A2F. WORKS OK!
' Both interrupts staggered 30 secs apart.
' RTC Address definitions
' ========================
SecReg CON $00 ' seconds address (00 - 59)
' MSB of SecReg must be set to a 0 to enable RTC
MinReg CON $01 ' minutes address (00 - 59)
HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
DayReg CON $03 ' day address (1 - 7)
DateReg CON $04 ' date address (01 - 28/29, 30, 31)
MonthReg CON $05 ' month address (01 - 12)
YearReg CON $06 ' year address (00 - 99)
' Alarm 1 Address definitions
' ===========================
Alm1sec CON $07 ' Alarm 1 seconds address (00 - 59)
Alm1min CON $08 ' Alarm 1 minutes address (00 - 59)
Alm1hr CON $09 ' Alarm 1 hours address (01 - 12) or (00 - 23)
Alm1Day CON $0A ' Alarm 1 day address (1 - 7)
' Alarm 2 Address definitions
' ===========================
Alm2min CON $0B ' Alarm 2 minutes address (00 - 59)
Alm2hr CON $0C ' Alarm 2 hours address (01 - 12) or (00 - 23)
Alm2Day CON $0D ' Alarm 2 day address (1 - 7)
' Alias of Clock register addresses
' =================================
ContReg CON $0E ' CONTROL register address
StatusReg CON $0F ' STATUS register address
' Clock Variables
' ================
sec VAR BYTE ' seconds
MINs VAR BYTE ' minutes
hr VAR BYTE ' hours
day VAR BYTE ' day
date VAR BYTE ' date
mon VAR BYTE ' month
yr VAR BYTE ' year
' ALARM1 VARIABLES
' ================
A1sec VAR BYTE ' seconds
A1MINs VAR BYTE ' minutes
A1hr VAR BYTE ' hours
A1day VAR BYTE ' day
' ALARM2 VARIABLES
' ================
A2MINs VAR BYTE ' minutes
A2hr VAR BYTE ' hours
A2day VAR BYTE ' day
GoSub SetTimeAndDate ' Setup current time & alarm settings
'*----------------SETUP FOR USING USB INTERFACE-------------------------
'***********************************************************************
INCLUDE "DT_HID260.pbp"
DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Mister E/DT"
DEFINE USB_PRODUCTNAME "USBDemo"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10
; --- Each USB status LED is optional, comment them if not used ---------
; ---They can be assigned to any pin, and no further action is required --
;DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
;DEFINE USB_PLUGGEDLED PORTB,7 ; LED indicates if USB is connected
;DEFINE USB_TXLED PORTB,6 ; " " data being sent to PC
;DEFINE USB_RXLED PORTB,5 ; " " data being received from PC
;--- Variables ----------------------------------------------------------
Value0 VAR WORD
Value1 VAR WORD
X VAR WORD
DUTY1 VAR WORD
DUTY2 VAR WORD
Old_PORTA VAR BYTE
New_PORTA VAR BYTE
;--- Setup ADC ----------------------------------------------------------
DEFINE ADC_BITS 8 ; Number of bits in ADCIN result
;--- Initialize ---------------------------------------------------------
CCPR1L = 0
CCPR2L = 0
CCP1CON = %00001100 ' CCP1, PWM mode
CCP2CON = %00001100 ' CCP2, PWM mode
PR2 = 249 ' 0-1000 duty range
T2CON = %00000101 ' TMR2 on, prescaler 1:4
TRISB = 0
OUTPUT PORTC.1
OUTPUT PORTC.2
ADCON2.7 = 0 ; left justify (Change this if ADFM in diff register)
ADCON1 = %1101 ; AN0/AN1 Analog
'------------------------SETTINGS FOR INTERRUPTS------------------------
'***********************************************************************
'Set interrupt related registers
RCON.7 = 1 ' Set Interrupt Priority Enable bit (Bit7=IPEN)
' to enable priority levels on interrupts
INTCON.7 = 1 ' Set Global Interrupt Enable bit
INTCON.6 = 1 ' Set PEIE to enable low priority periph interrupts
INTCON2 = %10001000 ' Enable PORTB Pull-ups (Bit7-high), set INTEG2
' for falling edge (Bit4-low) on RTC's interrupt.
INTCON3 = %10001000 ' Set INT2IP high priority (Bit7-high),
' enable INT2IE for interrupt(Bit4-high)
RTC_INT_FLG VAR INTCON3.1 'Alias for RB4 INTA interrupt from RTC
'Setup external interrupt macros
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
INT_Handler INT2_INT, _Alarm, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT2_INT ; enable external (INT) interrupts
' -----------------------BEGIN MAIN PROGRAM LOOP-----------------------
'***********************************************************************
Main:
Pause 1000
IF Plugged = 1 THEN
HIGH PORTC.6
GOTO USB ' USB cable is plugged-in
ENDIF
' Else, do other things if not connected
' If Alarm interrupt, read current time & ALARM settings from DS1337
' Perform range measurements if Midnight
LOW PORTC.6
USB:
'Process data from EEPROM to PC via USB interface
GoTo Main ' Endless Loop
End ' Safety measure to insure program stops if reaches here
'--------------------( Begin Interrupt Handler )------------------------
'***********************************************************************
Alarm:
HIGH PORTC.7 ' Test LED if Interupt
' Put code here to service the Alarm interrupt
LOW PORTC.7
' Resume Main Program
@ INT_RETURN
End ' Safety measure to insure program stops if reaches here
'------------------{ End of Interrupt Handler }---------------------------
' START LIST OF SUBROUTINES
'**************************
Bookmarks