News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Les USB routine

Started by Yves, May 13, 2022, 06:05 AM

Previous topic - Next topic

Yves

Hello All

I have slightly modified Les USB_ADC sample by placing the USB routine into an inc file. It works well as is but if I want to run it only once by removing the the Do...Loop at lines 14 and 21 the connection dropped. I tried many variations to try to get it sending only once whenever I need to call it which will make the routine useful to integrate in a main program. When I check with USBDview it shows that the USB is still code USB_ADC.zip connected. Where I am going wrong? See the code attached. Please help.

Regards,

Yves 
Yves

Yasin

As far as I know, you cannot use the usb connection like this. The connection between them and the computer needs to be polled. Otherwise, the connection with the computer (host) is disconnect.

Yves

So does it means that you have to run the USBpoll immediately before using the USB? like this:

Repeat
 USBpoll
Until USB_tConnected = 1 Or USB_tConfigured = 1


Yves
Yves

trastikata

Quote from: Yves on May 14, 2022, 06:04 AMSo does it means that you have to run the USBpoll immediately before using the USB? like this:

No, you have to poll the the connection about every 1 ms (specifications say 10ms but it sometimes creates problems) to keep the connection alive.

Otherwise if you want to use the  USB connection irregularly for sending none time critical packets, you will have to disconnect the USB, disable the USB module, then re-enable when needed and reconnect again by enumerating the device which takes seconds on the PC host side.

Yves

Thanks you for your explanation Trastikata if you have to to poll the connection every 1ms or so, it makes the routine unpractical. I have made an instrument that takes a series of readings every seconds and send them serially at 9600 baud to the PLX Daq excel micro using a USB to RS232 adaptor and automatically draws a chart. That works fine but I thought I could bypass the adaptor using the 18F2550 USB capability. At the moment I use USB to directly program the chip. Is there an alternative around this? I know I could add a USB to RS232 converter on the board.

Regards,

Yves     
Yves

Yasin

#5
Recommendation 1: Do your normal communication again in 1 second periods. Set a timer and have an empty polling before it exceeds 5ms seconds.
Recommendation 2: See post 13 in the link, which I have shared on the forum before.
https://protoncompiler.com/index.php/topic,540.msg3702.html#msg3702

https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices

Yves

Thanks Yasin,
I will work on it, you are right a time with an interrupt that poll the USB port should be the way forward.
Yves

tumbleweed

You should also move this part of your Send_to_com() routine out of the sub and into the main body of your code...
    DelayMS 10                                      ' Wait for things to stabilise
    USBInit                                         ' Initialise the USB peripheral

    Repeat                                          ' \
        USBPoll                                     '   Wait for the USB interface to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1 ' /

Once the device is connected and enumerated polling restrictions are more relaxed.

Yves

I'm knocking my head on my desk, I'm sure some of you knows the feeling.
I have tried to follow up the advice on the subject. I have implemented (I think) the interrupt ticking at 2.73ms using timer 1 which I got from an nice interface app called "PICTimerCalculator.exe". Put all code in the same body but I still not getting what I wanted which is be able to call the USB sending data when I want. It works if I use the do loop. USBDview shows that I have Com 9 when I connect the USB plug. Maybe my Interrupt handler is not doing what it should do. Any idea? I have attached the program below.
Many thanks for your time.
Yves
Yves

trastikata

#9
Yves,

This is how your program should look like ... your timer1 set-up looks like using the wrong clock source but I am too tired now to check the datasheets. Tomorrow is a new day, if somebody didn't answer before that I'll look into it.

Regards

On_Hardware_Interrupt GoTo Keep_USB_going ' Point to the interrupt handler
'------------------------------------------------------------------------
' The main program loop starts here
    T1CONbits_TMR1ON = 0

    USBInit                                             ' Initialise USB
    Repeat                                              ' \
        USBPoll                                         '   Wait for the USB interface to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1     ' /

    T1CONbits_TMR1ON = 1

 While
'     Toggle LED
'     delayms 1000
      Inc I
      Send_to_USB()
 Wend
'----------------------------------------------------------------------------
Sub Send_to_USB()
'    Do                                                  ' Create an infinite loop
         
        __USBOut_Buffer = "DATA, TIME, TIMER,"+","+ Str$(Dec,I)+","+ "\r"
'******************************************************************************
        Repeat
            USBOut 3, __USBOut_Buffer, Auto             ' Poll the USB and Transmit the buffer from endpoint 3
        Until Carry_Flag = 0                            ' Keep trying if the microcontroller does not have control over the buffer

'    Loop                                                ' Go wait for the next buffer input
EndSub
'--------------------------- Interrupt handler for USB ------------------------
Keep_USB_going:
Context Save ' Save any variables used in the interrupt
If PIR1bits_TMR1IF = 1 Then ' Is it a Timer1 overflow interrupt?

  USBPoll

 PIR1bits_TMR1IF = 0 ' Clear the Timer1 Overflow flag
EndIf
Context Restore ' Restore any variables and exit the interrupt

trastikata

Hello again Yves,

as I suspected your Timer1 set-up was wrong, also I modified the program as it should be.

Regards

(*
 Recommendation 1: Do your normal communication again in 1 second periods. Set a timer and have an empty polling before it exceeds 5ms seconds.
Recommendation 2: See post 13 in the link, which I have shared on the forum before.
https://protoncompiler.com/index.php/topic,540.msg3702.html#msg3702

https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices
*)

                                 
    Device = 18F2550                                    ' Choose a device with on-board full speed USB
    Declare Xtal = 48                                   ' Set the oscillator speed to 48MHz
    Declare Reminders = Off                             ' Disable all reminders
    Declare Warnings = Off
    Declare Reminders = Off
    Declare Optimiser_Level = 0
    Symbol LED = PORTC.1
    Include "CDC_Descriptor.inc"                        ' Include the CDC descriptors and the USB routines

    Dim MyWord As Word                                  ' General purpose variable
    Dim Out_Buffer As String * 20                       ' Used to hold some output characters
    Dim I As Byte
    Symbol Carry_Flag = STATUS.0                        ' Set if microcontroller does not have control over the DP buffer

' Timer1 Registers:
' Prescaler=1:2; TMR1 Preset=0; Freq=366.21094Hz; Period=2.7306667 ms
T1CONbits_RD16 = 1 ' Enable read/write of Timer1 in 16-bit mode
T1CONbits_T1CKPS1 = 0 ' \ Timer1 Prescaler to 1:2
T1CONbits_T1CKPS0 = 1 ' /
T1CONbits_T1OSCEN = 0 ' Disable External Oscillator
T1CONbits_TMR1CS  = 0 ' Increment on the internal Clock
T1CONbits_TMR1ON  = 0 ' bit 0 enables timer
TMR1H = $0      ' preset for timer1 MSB register
TMR1L = $0      ' preset for timer1 LSB register

PIE1bits_TMR1IE = 1 ' Enable the Timer1 overflow interrupt
INTCONbits_GIE = 1 ' Enable all interrupts
IPR1bits_TMR1IP = 1 ' Timer1 Overflow Interrupt to High priority
RCONbits_IPEN = 1 ' Enable priority levels on interrupts
wTimer1 = 0 ' Clear Timer1

Dim wTimer1 As TMR1L.Word ' Create a 16-bit Word from registers TMR1L/H
On_Hardware_Interrupt GoTo Keep_USB_going ' Point to the interrupt handler
'------------------------------------------------------------------------
' The main program loop starts here
    T1CONbits_TMR1ON  = 0                               'TMR1 OFF
   
    DelayMS 10                                          ' Wait for things to stabilise
    USBInit                                             ' Initialise USB
    Repeat                                              ' \
        USBPoll                                         '   Wait for the USB interface to become attached
    Until USB_tConnected = 1                ' /
   
    T1CONbits_TMR1ON  = 1                               'TMR1 ON

    While
        Toggle LED
        DelayMS 1000
        Inc I
        Send_to_USB()
    Wend
'----------------------------------------------------------------------------
Sub Send_to_USB()
'    Do                                                  ' Create an infinite loop
         
        __USBOut_Buffer = "DATA, TIME, TIMER,"+","+ Str$(Dec,I)+","+ "\r"
'******************************************************************************
        Repeat
            USBOut 3, __USBOut_Buffer, Auto             ' Poll the USB and Transmit the buffer from endpoint 3
        Until Carry_Flag = 0                            ' Keep trying if the microcontroller does not have control over the buffer

'    Loop                                                ' Go wait for the next buffer input
EndSub
'--------------------------- Interrupt handler for USB ------------------------
Keep_USB_going:
    Context Save ' Save any variables used in the interrupt
        If PIR1bits_TMR1IF = 1 Then ' Is it a Timer1 overflow interrupt?
            USBPoll                                       
            PIR1bits_TMR1IF = 0 ' Clear the Timer1 Overflow flag
        EndIf
    Context Restore ' Restore any variables and exit the interrupt
'------------------------------------------------------------------------------------------------
' Configure the 18F2550 for operation at 48MHz using a 20MHz crystal

Config_Start
 PLLDIV = 5           ;Divide by 5 (20 MHz oscillator input)
 CPUDIV = OSC1_PLL2   ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
 USBDIV = 2           ;USB clock source comes from the 96 MHz PLL divided by 2
 FOSC = HSPLL_HS       ;HS oscillator, PLL enabled (HSPLL)
 FCMEN = OFF ' Fail-Safe Clock Monitor disabled
 IESO = OFF ' Oscillator Switchover mode disabled
 PWRT = On ' PWRT enabled
 BOR = On ' Brown-out Reset enabled in hardware only
 BORV = 3 ' Brown-out Voltage bits: Minimum setting
 VREGEN = On           ;USB voltage regulator enabled
 WDT = OFF ' Watchdog Timer Disabled - SW Controlled
 WDTPS = 128 ' Watchdog Timer Postscale Select bits: 1:128
 MCLRE = On ' MCLR pin enabled, RE3 input pin disabled
 LPT1OSC = On ' Timer1 configured for low-power operation
 PBADEN = OFF ' PORTB<4:0> pins are configured as digital I/O on Reset
 CCP2MX = On ' CCP2 input/output is multiplexed with RC1
 STVREN = OFF ' Stack full/underflow will not cause Reset
 LVP = OFF ' Single-Supply ICSP disabled
 XINST = OFF ' Instruction set extension disabled
 Debug = OFF ' Background debugger disabled
 Cp0 = OFF ' Block 0 (000800-001FFFh) not code-protected
 CP1 = OFF ' Block 1 (002000-003FFFh) not code-protected
 CP2 = OFF ' Block 2 (004000-005FFFh) not code-protected
 CP3 = OFF ' Block 3 (006000-007FFFh) not code-protected
 CPB = OFF ' Boot block (000000-0007FFh) not code-protected
 CPD = OFF ' Data EEPROM not code-protected
 WRT0 = OFF ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = OFF ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = OFF ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = OFF ' Block 3 (006000-007FFFh) not write-protected
 WRTB = OFF ' Boot block (000000-0007FFh) not write-protected
 WRTC = OFF ' Config registers (300000-3000FFh) not write-protected
 WRTD = OFF ' Data EEPROM not write-protected
 EBTR0 = OFF ' Block 0 not protected from table reads
 EBTR1 = OFF ' Block 1 not protected
 EBTR2 = OFF ' Block 2 not protected
 EBTR3 = OFF ' Block 3 not protected
 EBTRB = OFF ' Boot block not protected
Config_End

Yves

Trastikata, I really appreciate your support but I tested your code but unfortunately it still not working.

Regards,

Yves
Yves

trastikata

Quote from: Yves on May 15, 2022, 07:23 AMTrastikata, I really appreciate your support but I tested your code but unfortunately it still not working.

Did the connection drop again or it did not connect at all?

Try this polled delay code (TMR1 is off) first if it works:

(*
 Recommendation 1: Do your normal communication again in 1 second periods. Set a timer and have an empty polling before it exceeds 5ms seconds.
Recommendation 2: See post 13 in the link, which I have shared on the forum before.
https://protoncompiler.com/index.php/topic,540.msg3702.html#msg3702

https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices
*)

                                 
    Device = 18F2550                                    ' Choose a device with on-board full speed USB
    Declare Xtal = 48                                   ' Set the oscillator speed to 48MHz
    Declare Reminders = Off                             ' Disable all reminders
    Declare Warnings = Off
    Declare Reminders = Off
    Declare Optimiser_Level = 0
    Symbol LED = PORTC.1
    Include "CDC_Descriptor.inc"                        ' Include the CDC descriptors and the USB routines

    Dim MyWord As Word                                  ' General purpose variable
    Dim Out_Buffer As String * 20                       ' Used to hold some output characters
    Dim I As Byte
    Symbol Carry_Flag = STATUS.0                        ' Set if microcontroller does not have control over the DP buffer
   
    Dim a As Word

' Timer1 Registers:
' Prescaler=1:2; TMR1 Preset=0; Freq=366.21094Hz; Period=2.7306667 ms
T1CONbits_RD16 = 1 ' Enable read/write of Timer1 in 16-bit mode
T1CONbits_T1CKPS1 = 0 ' \ Timer1 Prescaler to 1:2
T1CONbits_T1CKPS0 = 1 ' /
T1CONbits_T1OSCEN = 0 ' Disable External Oscillator
T1CONbits_TMR1CS  = 0 ' Increment on the internal Clock
T1CONbits_TMR1ON  = 0 ' bit 0 enables timer
TMR1H = $0      ' preset for timer1 MSB register
TMR1L = $0      ' preset for timer1 LSB register

PIE1bits_TMR1IE = 1 ' Enable the Timer1 overflow interrupt
INTCONbits_GIE = 1 ' Enable all interrupts
IPR1bits_TMR1IP = 1 ' Timer1 Overflow Interrupt to High priority
RCONbits_IPEN = 1 ' Enable priority levels on interrupts
wTimer1 = 0 ' Clear Timer1

Dim wTimer1 As TMR1L.Word ' Create a 16-bit Word from registers TMR1L/H
On_Hardware_Interrupt GoTo Keep_USB_going ' Point to the interrupt handler
'------------------------------------------------------------------------
' The main program loop starts here
    T1CONbits_TMR1ON  = 0                               'TMR1 OFF
   
    DelayMS 10                                          ' Wait for things to stabilise
    USBInit                                             ' Initialise USB
    Repeat                                              ' \
        USBPoll                                         '   Wait for the USB interface to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1     ' /
   
    T1CONbits_TMR1ON  = 0                               'TMR1 ON

    While
        Toggle LED
        For a = 0 To 999
            DelayMS 1
            USBPoll
        Next
        Inc I
        Send_to_USB()
    Wend
'----------------------------------------------------------------------------
Sub Send_to_USB()
'    Do                                                  ' Create an infinite loop
         
        __USBOut_Buffer = "DATA, TIME, TIMER,"+","+ Str$(Dec,I)+","+ "\r"
'******************************************************************************
        Repeat
            USBOut 3, __USBOut_Buffer, Auto             ' Poll the USB and Transmit the buffer from endpoint 3
        Until Carry_Flag = 0                            ' Keep trying if the microcontroller does not have control over the buffer

'    Loop                                                ' Go wait for the next buffer input
EndSub
'--------------------------- Interrupt handler for USB ------------------------
Keep_USB_going:
    Context Save ' Save any variables used in the interrupt
        If PIR1bits_TMR1IF = 1 Then ' Is it a Timer1 overflow interrupt?
            USBPoll                                       
            PIR1bits_TMR1IF = 0 ' Clear the Timer1 Overflow flag
        EndIf
    Context Restore ' Restore any variables and exit the interrupt
'------------------------------------------------------------------------------------------------
' Configure the 18F2550 for operation at 48MHz using a 20MHz crystal

Config_Start
 PLLDIV = 5           ;Divide by 5 (20 MHz oscillator input)
 CPUDIV = OSC1_PLL2   ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
 USBDIV = 2           ;USB clock source comes from the 96 MHz PLL divided by 2
 FOSC = HSPLL_HS       ;HS oscillator, PLL enabled (HSPLL)
 FCMEN = OFF ' Fail-Safe Clock Monitor disabled
 IESO = OFF ' Oscillator Switchover mode disabled
 PWRT = On ' PWRT enabled
 BOR = On ' Brown-out Reset enabled in hardware only
 BORV = 3 ' Brown-out Voltage bits: Minimum setting
 VREGEN = On           ;USB voltage regulator enabled
 WDT = OFF ' Watchdog Timer Disabled - SW Controlled
 WDTPS = 128 ' Watchdog Timer Postscale Select bits: 1:128
 MCLRE = On ' MCLR pin enabled, RE3 input pin disabled
 LPT1OSC = On ' Timer1 configured for low-power operation
 PBADEN = OFF ' PORTB<4:0> pins are configured as digital I/O on Reset
 CCP2MX = On ' CCP2 input/output is multiplexed with RC1
 STVREN = OFF ' Stack full/underflow will not cause Reset
 LVP = OFF ' Single-Supply ICSP disabled
 XINST = OFF ' Instruction set extension disabled
 Debug = OFF ' Background debugger disabled
 Cp0 = OFF ' Block 0 (000800-001FFFh) not code-protected
 CP1 = OFF ' Block 1 (002000-003FFFh) not code-protected
 CP2 = OFF ' Block 2 (004000-005FFFh) not code-protected
 CP3 = OFF ' Block 3 (006000-007FFFh) not code-protected
 CPB = OFF ' Boot block (000000-0007FFh) not code-protected
 CPD = OFF ' Data EEPROM not code-protected
 WRT0 = OFF ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = OFF ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = OFF ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = OFF ' Block 3 (006000-007FFFh) not write-protected
 WRTB = OFF ' Boot block (000000-0007FFh) not write-protected
 WRTC = OFF ' Config registers (300000-3000FFh) not write-protected
 WRTD = OFF ' Data EEPROM not write-protected
 EBTR0 = OFF ' Block 0 not protected from table reads
 EBTR1 = OFF ' Block 1 not protected
 EBTR2 = OFF ' Block 2 not protected
 EBTR3 = OFF ' Block 3 not protected
 EBTRB = OFF ' Boot block not protected
Config_End

Yves

In your previous version the COM 9 was showing but it didn't work. It only worked when the do .. loop is activated. Your latest code which I simply copied and paste and load with Pickit3,  USBDview saying the Configuration Descriptor Failed so no COM communication is possible, even after pulling the USB plug in and out or resetting the chip.

Yves
Yves

towlerg

#14
I think you're misunderstanding poll. See following snippet from Samples. Providing your in a loop looking for data or sending data, you don't need to poll.

Main:
    OSCTUNEbits_PLLEN = 1                               ' Enable the device's PLL
    Clear                                               ' Clear all RAM before we start
    All_Digital = True                                  ' Set PORTA and PORTD to digital mode
    DelayMS 10                                          ' Wait for things to stabilise

    USBInit                                             ' Initialise USB
    Repeat                                              ' \
        USBPoll                                         '   Wait for the USB interface to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1     ' /

I think the polling you're ruminating is a function of enumeration (thats why the snippet above sits in a tight "wait to connect" loop.

Yves

Towlerg,
the  OSCTUNEbits_PLLEN = 1  is not found in 18F2550. The problem is not getting the USB to send data or to have the COM port open, that works fine. It is to avoid the the connection dropping when the program is doing something else and send data only at will when the data are collected every seconds or so. Trastikata's suggestion using an interrupt to keep the connection on by polling the USB in less than 10ms,is on the right path but maybe the timing is not yet right. In Les original USB18Com.bas is working fine as it is waiting in USBIn to send a character but I don't think I can do that using the excel PLX-DAQ from Parallax.
Surely someone in the Positron group has figure it out?
Regards,

Yves

Yves
Yves

trastikata

#16
Quote from: Yves on May 15, 2022, 07:23 AMTrastikata, I really appreciate your support but I tested your code but unfortunately it still not working.

Yves,

I tested the code on an old USB capable PIC18F2553 (this is the same as PIC18F2550 but has 12bit ADC, the rest is virtually the same and the hex files can be used on any of both) device I have and it works. Check your terminal program, some of them are iffy with the CDC drivers. I am posting the code I used and a screenshot of the terminal program showing COM port 4 used as virtual port and the data in.

Regards

USB.jpg

(*
 Recommendation 1: Do your normal communication again in 1 second periods. Set a timer and have an empty polling before it exceeds 5ms seconds.
Recommendation 2: See post 13 in the link, which I have shared on the forum before.
https://protoncompiler.com/index.php/topic,540.msg3702.html#msg3702

https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices
*)

                                 
    Device = 18F2550                                    ' Choose a device with on-board full speed USB
    Declare Xtal = 48                                   ' Set the oscillator speed to 48MHz
    Declare Reminders = Off                             ' Disable all reminders
    Declare Warnings = Off
    Declare Reminders = Off
    Declare Optimiser_Level = 0
    Symbol LED = PORTC.1
    Include "CDC_Descriptor.inc"                        ' Include the CDC descriptors and the USB routines

    Dim MyWord As Word                                  ' General purpose variable
    Dim Out_Buffer As String * 20                       ' Used to hold some output characters
    Dim I As Byte
    Symbol Carry_Flag = STATUS.0                        ' Set if microcontroller does not have control over the DP buffer
   
    Dim a As Word

' Timer1 Registers:
' Prescaler=1:2; TMR1 Preset=0; Freq=366.21094Hz; Period=2.7306667 ms
T1CONbits_RD16 = 1 ' Enable read/write of Timer1 in 16-bit mode
T1CONbits_T1CKPS1 = 0 ' \ Timer1 Prescaler to 1:2
T1CONbits_T1CKPS0 = 1 ' /
T1CONbits_T1OSCEN = 0 ' Disable External Oscillator
T1CONbits_TMR1CS  = 0 ' Increment on the internal Clock
T1CONbits_TMR1ON  = 0 ' bit 0 enables timer
TMR1H = $0      ' preset for timer1 MSB register
TMR1L = $0      ' preset for timer1 LSB register

PIE1bits_TMR1IE = 1 ' Enable the Timer1 overflow interrupt
INTCONbits_GIE = 1 ' Enable all interrupts
IPR1bits_TMR1IP = 1 ' Timer1 Overflow Interrupt to High priority
RCONbits_IPEN = 1 ' Enable priority levels on interrupts
wTimer1 = 0 ' Clear Timer1

Dim wTimer1 As TMR1L.Word ' Create a 16-bit Word from registers TMR1L/H
On_Hardware_Interrupt GoTo Keep_USB_going ' Point to the interrupt handler
'------------------------------------------------------------------------
' The main program loop starts here
    T1CONbits_TMR1ON  = 0                               'TMR1 OFF
   
    DelayMS 10                                          ' Wait for things to stabilise
    USBInit                                             ' Initialise USB
    Repeat                                              ' \
        USBPoll                                         '   Wait for the USB interface to become attached
    Until USB_tConfigured = 1                           ' /
   
    T1CONbits_TMR1ON  = 1                               'TMR1 ON

    While
        Toggle LED
        DelayMS 1000
        Inc I
        Send_to_USB()
    Wend
'----------------------------------------------------------------------------
Sub Send_to_USB()
'    Do                                                  ' Create an infinite loop
         
        __USBOut_Buffer = "DATA, TIME, TIMER,"+","+ Str$(Dec,I)+","+ "\r"
'******************************************************************************
        Repeat
            USBOut 3, __USBOut_Buffer, Auto             ' Poll the USB and Transmit the buffer from endpoint 3
        Until Carry_Flag = 0                            ' Keep trying if the microcontroller does not have control over the buffer

'    Loop                                                ' Go wait for the next buffer input
EndSub
'--------------------------- Interrupt handler for USB ------------------------
Keep_USB_going:
    Context Save ' Save any variables used in the interrupt
        If PIR1bits_TMR1IF = 1 Then ' Is it a Timer1 overflow interrupt?
            USBPoll                                       
            PIR1bits_TMR1IF = 0 ' Clear the Timer1 Overflow flag
        EndIf
    Context Restore ' Restore any variables and exit the interrupt
'------------------------------------------------------------------------------------------------
' Configure the 18F2550 for operation at 48MHz using a 20MHz crystal

Config_Start
 PLLDIV = 5           ;Divide by 5 (20 MHz oscillator input)
 CPUDIV = OSC1_PLL2   ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
 USBDIV = 2           ;USB clock source comes from the 96 MHz PLL divided by 2
 FOSC = HSPLL_HS       ;HS oscillator, PLL enabled (HSPLL)
 FCMEN = OFF ' Fail-Safe Clock Monitor disabled
 IESO = OFF ' Oscillator Switchover mode disabled
 PWRT = On ' PWRT enabled
 BOR = On ' Brown-out Reset enabled in hardware only
 BORV = 3 ' Brown-out Voltage bits: Minimum setting
 VREGEN = On           ;USB voltage regulator enabled
 WDT = OFF ' Watchdog Timer Disabled - SW Controlled
 WDTPS = 128 ' Watchdog Timer Postscale Select bits: 1:128
 MCLRE = On ' MCLR pin enabled, RE3 input pin disabled
 LPT1OSC = On ' Timer1 configured for low-power operation
 PBADEN = OFF ' PORTB<4:0> pins are configured as digital I/O on Reset
 CCP2MX = On ' CCP2 input/output is multiplexed with RC1
 STVREN = OFF ' Stack full/underflow will not cause Reset
 LVP = OFF ' Single-Supply ICSP disabled
 XINST = OFF ' Instruction set extension disabled
 Debug = OFF ' Background debugger disabled
 Cp0 = OFF ' Block 0 (000800-001FFFh) not code-protected
 CP1 = OFF ' Block 1 (002000-003FFFh) not code-protected
 CP2 = OFF ' Block 2 (004000-005FFFh) not code-protected
 CP3 = OFF ' Block 3 (006000-007FFFh) not code-protected
 CPB = OFF ' Boot block (000000-0007FFh) not code-protected
 CPD = OFF ' Data EEPROM not code-protected
 WRT0 = OFF ' Block 0 (000800-001FFFh) not write-protected
 WRT1 = OFF ' Block 1 (002000-003FFFh) not write-protected
 WRT2 = OFF ' Block 2 (004000-005FFFh) not write-protected
 WRT3 = OFF ' Block 3 (006000-007FFFh) not write-protected
 WRTB = OFF ' Boot block (000000-0007FFh) not write-protected
 WRTC = OFF ' Config registers (300000-3000FFh) not write-protected
 WRTD = OFF ' Data EEPROM not write-protected
 EBTR0 = OFF ' Block 0 not protected from table reads
 EBTR1 = OFF ' Block 1 not protected
 EBTR2 = OFF ' Block 2 not protected
 EBTR3 = OFF ' Block 3 not protected
 EBTRB = OFF ' Boot block not protected
Config_End

Yves


Trastikata,
Wow,wow,wow, It works like a charm! After had programed the chip I tested it using using the Positron IDE's serial com and I couldn't connect though it shows clearly the com 9 was open. Then I downloaded the Termite 3.4 and I received data in a timely fashion. Maybe that was the problem all alone?
I can't thank you enough for your patience and perseverance also valuable help.

Kind regards,

Yves   
Yves

trastikata

Quote from: Yves on May 15, 2022, 02:00 PMThen I downloaded the Termite 3.4 and I received data in a timely fashion. Maybe that was the problem all alone?

I am pleased to hear it worked out.

It has been a while since I used the virtual COM port in any application and have forgotten that some terminal programs have problems opening virtual COM ports.

towlerg

"the  OSCTUNEbits_PLLEN = 1  is not found in 18F2550"

I picked a USB example from Samples at random, sorry don't know what device that example used and it really dosen't matter. I was trying to show the use of USBpoll.