News:

;) This forum is the property of Proton software developers

Main Menu

USB18 Com.bas form PDS example

Started by Yves, May 07, 2022, 08:21 PM

Previous topic - Next topic

Yves

Hello all,

I'm trying my hand on USB communication. I took Les code  in the examples from the  PDS folder. The only things I had to change is the 18F2550 instead of the 18F4550 and also I didn't have a 12Mhz crystal so I  used 8 Mhz instead. I think I made the right changes on the the CPU configuration to accommodate the 8 Mhz crystal. But the code is not compiling and gives me an error that I don't understand. Your help will be well appreciated. Bellow the zip code:
Regards,
YvesUSB18 Com.zip   
Yves

RGV250

#1
Hi,
It is to do with
QuoteICPRT = OFF         ' Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit: disabled
I would try it with that commented out or use fuse configurator to set new configs.

Have a look in the def's file or the datasheet.

Bob

Yves

Thank you Bob, Turning the ICPRT = OFF to On made the trick.

Now I'm getting a warning about the "At" in the USB_MemAlloc.inc for example:
' Endpoint 3, OUT and IN
$if (cUSB_MAX_EP_NUMBER = 3)
    Dim USB_dEp0Bo As Dword At ( _usb_ram +  4 * 0)
    Dim USB_dEp0Bi As Dword At ( _usb_ram +  4 * 1)
    Dim USB_dEp1Bo As Dword At ( _usb_ram +  4 * 2)
    Dim USB_dEp1Bi As Dword At ( _usb_ram +  4 * 3)
    Dim USB_dEp2Bo As Dword At ( _usb_ram +  4 * 4)
    Dim USB_dEp2Bi As Dword At ( _usb_ram +  4 * 5)
    Dim USB_dEp3Bo As Dword At ( _usb_ram +  4 * 6)
    Dim USB_dEp3Bi As Dword At ( _usb_ram +  4 * 7)
    Dim USB_wTemp As Word At USB_dEp3Bi + 4             ' Temporary storage
    etc.
after compiling I get something like: Warning: the 'At' directive is not an official part of the compiler's syntax and the compiler will not move around an addressed variable. Also the RAM position...

Shall I worry about that?

Yves
Yves

RGV250

It is a warning rather than a error, it say make sure the assembler ram location is suitable. As the code was written by Les I would not be concerned, I doubt it is any different to the 4550.

Bob

Yves

Thanks Bob, It would be interesting to heat what Less say about that warning. I'm always worry about warning I don't understand.

Cheers

Yves
Yves

top204

I added the message for the "At" directive because it was sometimes being misused.

I added the "At" directive for my own use when I was first developing the compiler, many years ago. So I could move variables around and test the RAM bank switching etc... And it came in very handy. However, if misused it can cause havok with a program's operation.

To remove the reminder messages and the warning messages, use the declares:

Declare Warnings = Off

and

Declare Reminders = Off

Yves

Thank you Les I did just that.
Now when I connect it to my PC with the USB18 com sample after connecting the USB plug I get on USBDview Hub3,port2. If I look at the device Manager page I get "Unknown USB device(Device descriptor Failed)" no com number. Is the descriptor not up to date? I'm using win10 operating system.

Regards,

Yves
Yves

towlerg

Resultant frequency (combo of crystal and fuse settings) is critical, either 48MHz or 24MHz. You must verify that you are using the correct value. Sorry don't have an example for 8MHz crystal. I always use 20MHz

$if _device = _18F4550 Or _device = _18F2550

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)
  VREGEN = On           ;USB voltage regulator enabled

Yves

Thank you Towlerg it just happen that I have 20Mhz crystals so I will have a go with your configuration.

Regards,

Yves
Yves

Yves

I have made the changes suggested above using a 20Mhz crystal but I still have  "Unknown USB device(Device descriptor Failed)"message in the device manager. I have checked the timing by blinking a LED for 10 seconds.
' General purpose USB CDC test program.
'
' Transmits data from several different buffers.
' And displays the contents of the Usbin buffer on the LCD
'
' Uses transmit and receive detection using the Carry flag (STATUS.0)
'
' Communicate via the serial terminal set to the com port that the USB connects too.
'
' Written by Les Johnson for the Positron8 BASIC compiler.
' https://sites.google.com/view/rosetta-tech/home
'
Declare Reminders = Off                                 ' Disable all reminders
    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 LCD_DTPin = PORTD.0                         ' LCD data port attached to PORTD
'    Declare LCD_RSPin = PORTE.0                         ' LCD RS pin attached to PORTE.0
'    Declare LCD_ENPin = PORTE.1                         ' LCD EN pin attached to PORTE.1
'    Declare LCD_Interface = 4                           ' 4-bit Interface
'    Declare LCD_Lines = 2                               ' 2 line LCD
'    Declare LCD_Type = Alphanumeric                     ' Use an Hitachi alphanumeric LCD
    Symbol LED = PORTC.1
    Include "CDC_Descriptor.inc"                        ' Include the CDC descriptors and the USB routines

    Dim MyWord As Word                                  ' General purpose variable
    Dim Array1[20] As Byte                              ' Used to hold some output characters
    Dim Out_Buffer As String * 20                       ' Used to hold some output characters
    Dim In_Buffer As String * 20                        ' Used to hold some input characters
    Dim Code_String As Code = " Code Memory Buffer\n\r",0

    Symbol Carry_Flag = STATUS.0                        ' Set if microcontroller does not have control over the DP buffer

'------------------------------------------------------------------------
' The main program loop starts here
'
' while
' toggle LED
' delayms 10000
' wend
Main:
    DelayMS 10                                          ' Wait for things to stabilise
    Clear                                               ' Clear all RAM before we start
    Cls                                                 ' Clear the LCD

    USBInit                                             ' Initialise USB

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

    Array1 = " Array Buffer\n\r"                        ' Fill the array with Null terminated characters
    Out_Buffer = " String Buffer\n\r"                   ' Fill the string with Null terminated characters

    MyWord = 0                                          ' Reset the counting variable
    Do                                                  ' Create an infinite loop
        Repeat                                          ' Wait for USB input
            USBIn 3, In_Buffer, Auto                    ' Poll the USB and Receive some data from endpoint 3
        Until Carry_Flag = 0                            ' Keep looking until data is able to be received

'        Print At 1,1,"USB Buffer"
'        Print At 2,1,In_Buffer                          ' Display the contents of the USB buffer on line 2 of the LCD
        Clear In_Buffer                                 ' Then clear the buffer for the next time

        __USBOut_Buffer = " USB Buffer\n\r"             ' Place characters directly into the USB TX buffer string
        '
        ' Transmit from the USB's internal TX buffer String. Null terminated.
        '
        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
        '
        ' Transmit from a Null terminated array
        '
        Repeat
            USBOut 3, Array1, 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
        '
        ' Transmit from a Null terminated String
        '
        Repeat
            USBOut 3, Out_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
        '
        ' Transmit from a Null terminated code memory String
        '
        Repeat
            USBOut 3, Code_String, 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
        '
        ' Transmit a Null terminated quoted string of characters
        '
        Repeat
            USBOut 3, " Quoted String\n\r", 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
        '
        ' Transmit 12 characters from a code memory String
        '
        Repeat
            USBOut 3, Code_String, 12                   ' Poll the USB and Transmit only 12 characters of the buffer from endpoint 3
        Until Carry_Flag = 0                            ' Keep trying if the microcontroller does not have control over the buffer

        __USBOut_Buffer = "\n\rVAR1 = " + Str$(Dec,MyWord) + "\n\r"  ' Convert MyWord into a string
        '
        ' Transmit from the USB's internal TX buffer String. Null terminated.
        '
        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
        Inc MyWord
    Loop                                                ' Go wait for the next buffer input

'------------------------------------------------------------------------------------------------
' 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

Cheers Yves   
Yves

joesaliba

Yves,

I remember I have this problem with 18F2550, but it is ok with the 18F4550.

I remember Les mentioning a declare for USB but I cannot find it in manual and forum.

It looks that USB with this device has been around for some time now: - https://protoncompiler.com/index.php/topic,85.msg327.html#msg327

But I remember that I used the 18F2550 USB with success with old versions of the compiler.

Regards

Joe

towlerg

#11
As everyone who have read my posts, not the sharpest knife in the box, but I've never had a problem substituting a 2550 for a 4550. Also I prefer the alternate (Les clone of mc's USB) version of Proton USB but probably best if you get built-in working first.

I've attached a know working USB mouse simulator prog, slightly modded from Les's. Sorry don't have time to (busy, busy doing nothing) correction to lazy, to go thro the zip and remove the superfluous.

Yves

Thank you Towlerg, but The HID driver modified or not is not recognize either. What I need is a "simple" USB CDC driver where I can transmit data through a virtual com port. From this I will use VBA to capture in in excel. Is it possible with Positron? so far all examples given didn't work.

Regards,

Yves   
Yves

Yves

Sorry guys I'm stuck, is anyone managed to get CDC seen as rs232 working? Usually Les samples codes works fine and from this backbone great understanding how things works can be acheived. I think I setup the clocking right for the USB.im now using 20Mhz crystal but I have 4,8,12 and 16 too.Could it be the protocol has changed in windows 10? Please, I need your help. Thank you.

Regards,
Yves
Yves

Yasin

Hello, unfortunately I don't have an mcu to test. The problem could be windows10 driver signing issue.
First suggestion. Using the advanced launch options. Disabling driver signing and trying to install the driver.
Suggest the two. Take a look here. https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-driver-installation-based-on-compatible-ids

Yves

Problem sorted

Hello all,
Thank you for your support. I build the test using a breadboard and realized I made a boo-boo by inverting the D+ and D- connections. Now everything is working as intended. I'm sorry for my silly mistake.

Regards,

Yves 
Yves