Hi Rob,
Nope, with PIC18F25K50 at 3.3V supply nothing workswith usb_serial library
except the echo part which is useless for me. Anything else is closing the
USB host port and device is seen as unknown.

About delay, please take a look at one good example of funlw65 (below)
where it has about 1 second delay by flushing in the meantime. However this
example is not relevant for using only the usb_serial because it uses the
bootloader  with different fuses configuration and different location for
the code which runs.
On PIC18F2550 at 5V supply and external HOSC, the actual USB library does
not send data reliably as an FT232 would do, an amount of data from ADC for
example would be sent to the terminal with variable speed even if the main
loop has  very simple structure with fixed computing time. Sometimes the
transmission stops, to resuscitate it,  the port has to be closed and
opened again on the host side...
I do not know why this happens, the library is too twisted for my taste so
perhaps I will modify it if I'll have nerves for that...



-- Project: ADC read and send on USB CDC
-- Author: Vasile Guta-Ciucur (funlw65)
-- License: Code released under New BSD license
-- For jallib libraries, see de licence inside jal.zip

include freejalduino4 -- FreeJALduino4 pinout layer for the last board model

-- include libraries
include usb_serial
include print
include format
include delay

var dword Value
var word AD_RESULT
var word Volts
-- var byte Millivolts
const byte str1[] = " Volts\n\r"


-- ==================================================
-- PROGRAM START ------------------------------------
-- ==================================================
-- configure pins
enable_digital_io() -- first, all pins set to digital


-- now configure ADC constants
const bit ADC_HIGH_RESOLUTION = true -- 10bit resolution
const byte ADC_NVREF = 0 -- no voltage reference
const byte ADC_NCHANNEL = 1 -- how many ADC channels we are using,
                            -- always starting the count from A0 (RA0/AN0)
                            -- This will automatically set A0 as analog
input
const word ADC_RSOURCE  = 909 -- impendance (R1*R2/(R1+R2))
-- then, load the ADC library
include adc
-- Initialize ADC
adc_init()


-- initialize the USB serial library
usb_serial_init()

-- start main loop
forever loop
  usb_serial_flush()
  AD_RESULT = adc_read(0)

  print_word_dec(usb_serial_data, AD_RESULT)
  usb_serial_data = " "


  -- Value = 537 * AD_RESULT
  Value = dword(537) * AD_RESULT -- one of the operands must be casted
                                 -- as dword to have a 32bit integer math
                                 -- because AD_RESULT is word and the other
                                 -- operand is a generic one.

  Volts = Value / 100

  format_word_dec(usb_serial_data, Volts, 4, 2)
  print_string(usb_serial_data, str1)

  for 100 loop -- delay 1 second (a little more than)
    usb_serial_flush()
    delay_1ms(10)
  end loop

end loop
--
On Sat, Feb 27, 2021 at 9:03 AM Rob CJ <[email protected]> wrote:

> Hi Vsurducan,
>
> Did you fix this issue? So far I never had issues with the USB driver but
> I had always used it with a crystal. Why are you using udc_cdc_putc()?
>
> About your other post about the USB driver. I saw that you used a delay of
> 400 ms in your main program. This may not work since the USB driver needs
> to be polled by usb_serial_flush() and this needs to be done quite
> frequently (I thought miliseconds).
>
> I already found this polling a bit anoying myself since it would be nicer
> to have it done on an interrupt basis. Some time ago I started to make it
> interrupt driven but it did not work immediately at that time. Maybe it is
> a good time to pick it up again.
>
> Kind regards,
>
> Rob
>
>
>
> ------------------------------
> *Van:* [email protected] <[email protected]> namens vsurducan
> <[email protected]>
> *Verzonden:* woensdag 24 februari 2021 20:33
> *Aan:* [email protected] <[email protected]>
> *Onderwerp:* Re: [jallib] WIN32CDCDrivers?
>
> Thank you Matt and Rob,
> I have a non reliable USB communication under both Win10 and Win7 so I'm
> suspecting everything...
> The following sample is based on 18F4550_USB_serial.jal. PIC18F25K50 has
> the same registers as PIC18F2550 except some PLL bits which can be ignored
> with a delay.
> However, USB works only with the echo. Trying to repeatedly send a byte
> from PIC to PC, communication it froze.
>
> include 18f25k50                     -- target PICmicro
> --
> -- This program assumes that a 16 MHz resonator or crystal
> -- is connected to pins OSC1 and OSC2.
> pragma target clock 48_000_000      -- oscillator frequency
> --
>
> pragma target OSC      HSH                       -- crystal or resonator
> pragma target PLLSEL   PLL3X
> pragma target PLLEN    ENABLED                   -- PLL on
> pragma target CPUDIV   P1                        -- Fosc divisor
> pragma target WDT      DISABLED                  -- watchdog
> pragma target XINST    DISABLED                  -- do not use extended
> instructionset
> pragma target DEBUG    DISABLED                  -- no debugging
> pragma target BROWNOUT DISABLED                  -- no brownout reset
> pragma target FCMEN    DISABLED                  -- no clock monitoring
> pragma target IESO     DISABLED                  -- no int/ext osc
> switching
> pragma target LVP      DISABLED                   -- low voltage
> programming
> pragma target MCLR     EXTERNAL                  -- external reset
> --
> -- The configuration bit settings above are only a selection, sufficient
> -- for this program. Other programs may need more or different settings.
> --
> OSCCON_SCS = 0                      -- select primary oscillator
> --
> enable_digital_io()                 -- make all pins digital I/O
> WDTCON_SWDTEN = OFF                     -- disable watchdog
>
> include delay
> include usb_serial
> include print
>
> -- constants
> const  byte str_welcome[] = "JALLIB USB Serial Demo app\n"
>
> -- variables
>
> -- interrupts? No thanks
> INTCON_GIE = false
>
> -- setup the USB serial library
> usb_serial_init()
>
> var bit has_shown_welcome_msg = true
> var byte ch
>
> -- main loop
> forever loop
> -- poll the usb ISR function on a regular base, in order to
> -- serve the USB requests
> usb_serial_flush()
>
>     -- check if USB device has been configured by the HOST
> if ( usb_cdc_line_status() !=  0x00 )  then
> if !has_shown_welcome_msg then
> has_shown_welcome_msg = true
> print_string( usb_serial_data, str_welcome )
> end if
> else
> has_shown_welcome_msg = false
> end if
>
> -- check for input character ; this works
>  if usb_serial_read( ch ) then
> -- echo input character
>     usb_serial_data = ch
>  end if
> ; none of the following works, the USB is frozen...
> ;    usb_cdc_putc ("B")
> ;    format_word_dec(usb_serial_data, 0x3FC , 4, 0)
> ;    print_byte_dec(usb_serial_data, 0x04)
>
>
>
> On Wed, Feb 24, 2021 at 9:02 PM Matt Schinkel <[email protected]>
> wrote:
>
> Hi, it is in jallib under tools/usb
>
> Sent from my Android device.
>
> ------------------------------
> *From:* [email protected] <[email protected]> on behalf of
> Rob CJ <[email protected]>
> *Sent:* Wednesday, February 24, 2021 1:41:57 PM
> *To:* [email protected] <[email protected]>
> *Subject:* Re: [jallib] WIN32CDCDrivers?
>
>  Hi Vsurducan,
>
> I do not know but I think you do not need them. When I updated the serial
> library some time ago I could test it with a JAL sample program. Windows 10
> recognized the usb device without the need for driver.
>
> If you use an older version of Windows I do not know if this is also true.
>
> Kind regards,
>
> Rob
>
> ------------------------------
> *Van:* [email protected] <[email protected]> namens vsurducan
> <[email protected]>
> *Verzonden:* woensdag 24 februari 2021 19:17
> *Aan:* [email protected] <[email protected]>
> *Onderwerp:* [jallib] WIN32CDCDrivers?
>
> Hi, where can I find a copy of  the Win32CDCDrivers.zip ?
> The links posted in the usb_serial_demo are broken.
> thanks,
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jallib/CAM%2Bj4quYAsdKiqVSCM%2BV6%2BaPFLvyeGj5WWfCgGnETB-e%2BW8wwQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/jallib/CAM%2Bj4quYAsdKiqVSCM%2BV6%2BaPFLvyeGj5WWfCgGnETB-e%2BW8wwQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jallib/AM0PR07MB6241E6D8D505B288C9B322B1E69F9%40AM0PR07MB6241.eurprd07.prod.outlook.com
> <https://groups.google.com/d/msgid/jallib/AM0PR07MB6241E6D8D505B288C9B322B1E69F9%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>
> .
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jallib/YQXPR01MB41496334B29E540ECA2A9766DE9F9%40YQXPR01MB4149.CANPRD01.PROD.OUTLOOK.COM
> <https://groups.google.com/d/msgid/jallib/YQXPR01MB41496334B29E540ECA2A9766DE9F9%40YQXPR01MB4149.CANPRD01.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jallib/CAM%2Bj4qtwEeyURARHT7%3Dc2%2BqE-w7AtFX0Hmyg%2ByJAOL7q%3DGCEAQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/jallib/CAM%2Bj4qtwEeyURARHT7%3Dc2%2BqE-w7AtFX0Hmyg%2ByJAOL7q%3DGCEAQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jallib/AM0PR07MB6241C7A557FE8743121FB378E69C9%40AM0PR07MB6241.eurprd07.prod.outlook.com
> <https://groups.google.com/d/msgid/jallib/AM0PR07MB6241C7A557FE8743121FB378E69C9%40AM0PR07MB6241.eurprd07.prod.outlook.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/CAM%2Bj4qvwzWBSCXT1RQEYEucBtW%2BSLYOinp%3DxSt6HZgKTnZ5ECA%40mail.gmail.com.

Reply via email to