Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

USB-MCU-USB loop

Status
Not open for further replies.

Mosaic

Well-Known Member
How doable is this: Serial data xfer on the same PC.

Terminal prg in XP via USB to a 16F886 MCU which does some processing and then data out back to another USB port and another instance of a Terminal prg?

Any advice on the approach?
 
I believe you only need 1 USB port for 2 way communication between a PC and an external peripheral. However I don't think the 16F series of PICs have USB capability but I could be way off base on this. Someone else with a bit more PIC experience may wanna chime in in regards to this.
 
Only one 16c745 and it's big brother 16c765 there one time programmable so you better have it right the first time.

If you want to use USB give Jalv2 a try it has usb library's and is well documented Just Another JAL Website | Just Another Language for your pic microcontroller

And get some 18f2550 chips the 18f14k50 is good to play with but make sure your getting new chip with the latest revision numbers on 18f14k50
 
You'd have to have a circuit that converts the serial UART data to USB format I would think. You cannot interface the UART directly to USB if that's what you're asking. Even then you'd only need one USB cable, but the circuit would have to have two inputs for RX and TX.
 
Use a USB/UART ic, like the FT232R or MCP2200, for each COM port required. Connect Rx to one, and Tx to the other if two are used. The MCP2200 is essentially a pre-programmed 18f14k50. The MCP2200 also needs to have XP SP3 installed, as I found out.
 
Are you all scared of Jalv2 or what? A 18f14k50 you can do USB your way easy as pie

Here a sample code
Code:
include 18f14k50

-- This file is the setup for my homebrew, 18f14k50 board
-- Currently it is a bare board, with just a PIC and a couple of headers
-- A 12 MHz external crystal and 15pf caps connected to OSC1/2
-- pin 17 (Vusb) with a 220 nF capacitor to the ground
-- The connection between PC and the 18F14k50
-- +5v to power the board (don't forget 100nf decoupling cap
-- data- wire to pin 18 (D-)
-- data+ wire to pin 19 (D+)
-- ground wire to the Vss of the PIC
-- even though the external crystal is 12 MHz, the configuration is such that
-- the CPU clock is derived from the 96 Mhz PLL clock (div2), therefore set
-- target frequency to 48 MHz
pragma target clock       48_000_000

-- fuses
pragma target CPUDIV        P1              -- NO_CPU_SYSTEM_CLOCK_DIVIDE
pragma target USBDIV        P1              -- USB_CLOCK_COMES_DIRECTLY_FROM_THE_OSC1_OSC2_OSCILLATOR_BLOCK_NO_DIVIDE
pragma target OSC           HS
pragma target PLLEN         P4              -- OSCILLATOR_MULTIPLIED_BY_4
pragma target FCMEN         DISABLED
pragma target IESO          DISABLED
pragma target PWRTE         DISABLED        -- power up timer
pragma target BROWNOUT      DISABLED        -- no brownout detection
pragma target VOLTAGE       V30             -- brown out voltage
pragma target WDT           DISABLED        -- no watchdog
pragma target WDTPS         P32K            -- watch dog saler setting
pragma target MCLR          EXTERNAL        -- external reset
pragma target LVP           DISABLED        -- no low-voltage programming
pragma target XINST         ENABLED         -- extended instruction set
pragma target DEBUG         DISABLED        -- background debugging
pragma target CP0           DISABLED        -- code block 0 not protected
pragma target CP1           DISABLED        -- code block 1 not protected
pragma target CPB           DISABLED        -- bootblock code not write protected
pragma target WRT0          DISABLED        -- table writeblock 0 not protected
pragma target WRT1          DISABLED        -- table write block 1 not protected
pragma target WRTB          DISABLED        -- bootblock not write protected
pragma target WRTC          DISABLED        -- config not write protected
pragma target EBTR0         DISABLED        -- table read block 0 not protected
pragma target EBTR1         DISABLED        -- table read block 1 not protected
pragma target EBTRB         DISABLED        -- boot block not protected
pragma target HFOFST        ENABLED         -- THE_SYSTEM_CLOCK_IS_HELD_OFF_UNTIL_THE_HFINTOSC_IS_STABLE


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
	if usb_serial_read( ch ) then
		-- echo input character
		usb_serial_data = ch
	end if
	
end loop
 
Not at all scared of JalV2, but my download of Jallib crapped out half way thru, and haven't started it back up. I am curious to see the USB library and others, when time allows, should be interesting. Microchip has a pre-compiled C18 demo for a Hid-Cdc device which does the very same thing, take your pic...:)
 
nickelflippr It's USB is great and if you can use Basic I think you said you use it You'll be right at home. The only bad thing is there not all on one site Here the whole thing I zip it up It's the latests just unzip go to the folder jaledit and run the ide jalEdit click on the help and you'll find all you need to get up and running with Jalv2
 
Last edited:
If you want to use two physical USB connections with the same uC, you will need two serial<->USB converters or a uC with two USB peripherals, or a combination of serial<->USB and USB peripheral. I don't know of any that have two USB peripherals, not that that means they don't exist. Otherwise it's not a problem.
 
nickelflippr It's USB is great and if you can use Basic I think you said you use it You'll be right at home. The only bad thing is there not all on one site Here the whole thing I zip it up It's the latests just unzip go to the folder jaledit and run the ide jalEdit click on the help and you'll find all you need to get up and running with Jalv2
Thanks for that Burt, have the Jalv2 compiler, and Jaledit already downloaded. Have slo-mo internet at the house, so maybe will download at the Java shop in the next couple of days.

And yes I like GCBasic, but from what I understand, the source code may (at this moment anyways) have some structural hurdles preventing a USB library. Really haven't had a need for USB in my projects, so more curiosity then a high priority.

The USB/UART chips would be the most versatile solution in terms of various compiler compatibility.
 
be80be:
Jal is nu to me...although I do have an 18f14k50 handy.

I was kinda hopin' to asm it, rather than learn another language. I have done GWbasic a long time ago though. Can u suggest an asm approach for the 18f14k50?

I see a guide in this link:
https://jallib.blogspot.com/2009/07/pic-18f14k50-usb-interface-board-part-4.html

But they suggest a 48Mhz clk speed. That may require a 4 layer board to manage crosstalk etc?

is a 48Mhz clk really required here?
 
Last edited:
You could use Swordfish BASIC but for USB you'll need the paid version. Else JALv2 or C18SE. There are no USB examples in asm that I've seen.

The PIC has a PLL multiplier you can choose from several osc frequencies from 4MHz on up.
 
Last edited:
be80be:
Jal is nu to me...although I do have an 18f14k50 handy.

I was kinda hopin' to asm it, rather than learn another language. I have done GWbasic a long time ago though. Can u suggest an asm approach for the 18f14k50?

I see a guide in this link:
jallib: PIC 18f14k50 USB Interface Board: Part 4

But they suggest a 48Mhz clk speed. That may require a 4 layer board to manage crosstalk etc?

is a 48Mhz clk really required here?

It don't you can bread board it it using pLL a 12 Mhz crystal with PLL set to 4 you could code it in asm download mircochip Usb stuff all 230MB of it and code away
 
Let me tell you A little some thing have you used Swordfish Basic I have it's only for the 18f chip I have a full copy so I can use USB with it I ran into Jalv2 about 3 months ago I didn't want to learn something new but Jalv2 had USB library And I didn't have a full copy of Swordfish then. So now I use both I can write for one and change just a little naming use it with swordfish there real close to working the same .

But jalv2 USB is so easy to use and it's free I almost wish I don't get Swordfish now. And I read a post last night that shed so light on why there so close

Any way by the time you get done coding USB in asm you could learn how to code in C C++ and VB.net LOL

And one more thing The documentions is some of the best only bad thing is that It's not all on one site there
there Jalv2 the compiler and the JaLibs the library then the Jaledit But they are getting it together at JaLibs
and making it easier to find all you need to get rolling
 
Last edited:
Yes they just added that but you have to no where to get it is the only thing that's a big show stopper.

If the pic can run it jalv2 can code it. Basically

Bill
That was slip but here a Ethernet one to when matt emails me back I'll let let know if you want it. I can't find it now it maybe 10000 emails back
 
Last edited:
I downloaded JALv2 and would like to learn it. However the only programming experience I have is in asm. Where the hell does one start? lol
 
Ok, JAL looks e-z enough, perhaps a week or 2 tops, and I do need to pick a HLL to use more 18f's. Does it compile well?

What about simulating it?
Is there any way to hook it into Proteus, to step through code etc?

Oh and can I mix asm with it for a tight routine here and there?


BTW this link for updating the ide etc is broken:

https://code.google.com/p/jallib/downloads/list
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top