[Solved] Directions to implement USB comm with 18F2550

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

[Solved] Directions to implement USB comm with 18F2550

#1 Post by MARIO » 23 Dec 2017 14:02

Merry Christmas to all.

I have never dealt with USB before. And I'm lost.
I need to read codes from a USB barcode scanner and turn on an alarm when the code is different from what is expected,. Simples as that.
But I have no clue how to do it. I'm just trying to get some directions on how to do it.

I got some information about devices and hosts. And I've read that I need an USB host to communicate to the scanner.

Is it possible to do it directly with PIC18F2550? If not, is there a way to do that?

As I mentioned before, it is a very simple project: read the code, compare it and activate an alarm if it is different.

Thanks in advance.
Last edited by MARIO on 26 Dec 2017 13:48, edited 1 time in total.
BR
EasyPic6 and registered mkC PRO FOR PIC since 2011
You're never too old to learn something stupid.(PARAPROSDOKIAN)

User avatar
strahinja.jacimovic
mikroElektronika team
Posts: 200
Joined: 18 Dec 2017 18:19

Re: Directions to implement USB comm with 18F2550

#2 Post by strahinja.jacimovic » 25 Dec 2017 12:24

Hi Mario,

Yes, it is possible and the code itself shouldn't be difficult to write.

You just need to compare the code you read with the expected code using an indefinite loop and activate some kind of alarm, be that a sound alarm or something else.

Most commonly a while(1) loop.

Here is a link to a 8051 example. The idea for reading is the same for PIC, you just have to add the part for comparison.
https://libstock.mikroe.com/projects/do ... c_8051.rar

I hope you can manage.

Kind regards,
Strahinja Jacimovic

PeDre
Posts: 27
Joined: 04 Oct 2010 07:16
Location: Austria

Re: Directions to implement USB comm with 18F2550

#3 Post by PeDre » 25 Dec 2017 20:21

The PIC18 models do not have a Host USB. The PIC24 models or higher have an OTG or Host USB, so it could be possible.

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Directions to implement USB comm with 18F2550

#4 Post by MARIO » 26 Dec 2017 02:01

I appreciate the answers.

@jacimovic

Thank you for your effort, but I think I did not make myself clear. Sorry for that.

The logic of comparison I know how to do it. The problem is to stablish communication with the scanner.

I've used the example of MkC Help, done some changes, but the scanner never sent anything to the PIC. That my problem. So, I need a host and, as PeDre said, 18F2550 alone is not able to!

What I was able to do is, using Proteus to simulate the Help example, a virtual port communication and the HID Terminal of MkE, the scanner started to read the codes and HID Terminal received them!

I've found that the IC, MAX3421E, is capable to do what I want, without upgrading the PIC family. Is that true?

I'm considering to use RS232 as the scanner allows it, which simplifies a lot, but my client needs to purchase a very specific cable and verify with the vendor if the scanner is specific to USB or can use RS232 too. I'm waiting for the answer.

And if I can be able to use RS232, I've already written a code that is working fine! Using a cheaper 16F628A. Used a RS232 Terminal to test it!

Thanks to you both.
BR
EasyPic6 and registered mkC PRO FOR PIC since 2011
You're never too old to learn something stupid.(PARAPROSDOKIAN)

User avatar
strahinja.jacimovic
mikroElektronika team
Posts: 200
Joined: 18 Dec 2017 18:19

Re: Directions to implement USB comm with 18F2550

#5 Post by strahinja.jacimovic » 26 Dec 2017 10:41

Hi,

The MAX3421E should be able to do what you need it to.

As I could see in the datasheet, it can work in both host and peripheral mode.

It has quite a lot of registers, so it wouldn't be quite easy to set up, but it can be done.

You set it to work in the desired mode by setting the HOST BIT in the MODE(R27) register.

Just be careful, because you need at least 12 MHz for it to work properly.

You can find the programming guide here: https://pdfserv.maximintegrated.com/en/an/AN3785.pdf

Bear in mind that SPI works in MSB first mode and in host mode some of the registers are renamed.

And can you give me the link to the scanner you are using?

Kind regards,
Strahinja Jacimovic

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Directions to implement USB comm with 18F2550

#6 Post by MARIO » 26 Dec 2017 13:04

Hi,

Thanks for the valuable information!

http://www.datalogic.com/eng/products/r ... d-160.html

I'm just trying to avoid additional costs in the project. It is cheaper to get RS232 cable, I suppose.

The last choice is using MAX3421E due other difficulties, including the cost of development as it is supposed to make only one or two of them!

Maybe FT232 can also be used as a host?

Thanks.

EDIT: I got the specific model and it is not multi-interface. It is only USB! :? :?
Last edited by MARIO on 26 Dec 2017 13:15, edited 1 time in total.
BR
EasyPic6 and registered mkC PRO FOR PIC since 2011
You're never too old to learn something stupid.(PARAPROSDOKIAN)

User avatar
strahinja.jacimovic
mikroElektronika team
Posts: 200
Joined: 18 Dec 2017 18:19

Re: Directions to implement USB comm with 18F2550

#7 Post by strahinja.jacimovic » 26 Dec 2017 13:13

Hi,

Yes, I do think that you can use it for your project as well as seen in the datasheet page 2:

http://www.ftdichip.com/Support/Documen ... FT232R.pdf

Whatever you choose should work. The question is how much are you willing to pay?

Kind regards,
Strahinja Jacimovic

MARIO
Posts: 978
Joined: 18 Aug 2008 22:13
Location: Brasil

Re: Directions to implement USB comm with 18F2550

#8 Post by MARIO » 26 Dec 2017 13:33

Hi.

Yes, but the cost is up to my client if it worths or not.

My job is to inform him the alternatives.

I'm just awaiting his response.

I really appreciate your efforts helping me.

Thanks.
BR
EasyPic6 and registered mkC PRO FOR PIC since 2011
You're never too old to learn something stupid.(PARAPROSDOKIAN)

User avatar
strahinja.jacimovic
mikroElektronika team
Posts: 200
Joined: 18 Dec 2017 18:19

Re: Directions to implement USB comm with 18F2550

#9 Post by strahinja.jacimovic » 26 Dec 2017 13:35

Hi,

No problem whatsoever.

We are glad to help here at mikroE.

Kind regards,
Strahinja Jacimovic

Post Reply

Return to “mikroC PRO for PIC General”