Help with USB ...

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Help with USB ...

Post by dzairo » Wed Sep 22, 2010 3:44 pm

Hi all.
I'm new on this forum.
I have plan to make small PCB with I2C display (http://www.sos.sk/?str=371&artnum=64822) and RFID 125kHz reader (http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=2702) for some easy small plastic box. Using ATmega8 or some else. I need help with V-USB , I want it as HID (no drivers need) other function (control LCD or read data from EMC4095 rfid reader) I have and use on other project and post for all who want (its free). I just want so user if give RFID card then MCU read this code show on LCD and if user over USB send request then MCU send to user IC card code.Also user can send any text in to LCD .

I make schematic, PCB and all for make this project , Is there any one for help with this?

regards.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Thu Sep 30, 2010 9:19 pm

dzairo wrote:I make schematic, PCB and all for make this project , Is there any one for help with this?

What exactly do you need help with? Seems to me that the HID-data example project that comes with the V-USB source, would be the perfect place to begin. :)

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Fri Oct 01, 2010 5:14 pm

Hi all.
I start with this project http://www.recursion.jp/avrcdc/cdc-232.html and connect LCD (now work) and connect RFID reader (too work but..) , RFID need work in interrupt mode , use T0.
But if use it with USB then can send data from MCU in to USB. I need disable T0 interrupt when want send data.
Is possible to help my where I must define disable T0 interupt and then again enable???
other question is .
is possible to make *.inc file for 24MHz crystal ???

regards

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Fri Oct 01, 2010 8:45 pm

dzairo wrote:Hi all.
I start with this project http://www.recursion.jp/avrcdc/cdc-232.html and connect LCD (now work) and connect RFID reader

That wouldn't have been my first choice given that it violates the standard for low-speed USB and it does require a driver (that doesn't work with 64-bit win vista/7) not to mention the overhead on the MCU. On the up-side, I guess it does make the PC coding a little easier...perhaps. Personally I thought your original idea of a driverless HID device was a much better choice.
dzairo wrote:RFID need work in interrupt mode , use T0.
But if use it with USB then can send data from MCU in to USB. I need disable T0 interrupt when want send data.
Is possible to help my where I must define disable T0 interupt and then again enable???

Can you not simply use a different interrupt for the RFID? T1 for example. I understand that would probably require modifying your PCB a little but I'd say it would be worth it in the end, compared to messing with the USB interrupt.
dzairo wrote:other question is .
is possible to make *.inc file for 24MHz crystal ???
regards

Someone else will have to answer that one. However, I do not understand why you want that when the project linked in your OP features ATmega32 @ 16MHz. Perhaps I missed something?

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Sat Oct 02, 2010 12:40 pm

Hi.
OK .
I can start with other project to work with HID but I want use my PCB with out of need program special software for programmers. IF use this CDC-232 project then can use driver and install it as standard serial port . and every can use it or just open hyper terminal and can communicate with my PCB as standard converter or use my own function .
now it work like this. if user set speed 600bps then all data are for my own function (send text to LCD, read data from RFID ..... .can add more function) but if set different speed then all work like standard usb serial port converter.
I just have problem with real time reading and decoding RFID tag. but try use 20MHz crystal and try found position where can I disable - enable interrupt what I need for RFID.

of course send me link to any easy HID device where can I send or receive data from to USB.
I look at it and try too.

regards

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Sat Oct 02, 2010 3:50 pm

Hi all.
I search on the web easy example for USB HID using.
But I don't find easy code.
question for all.
1. some code use only 2-avr pin some code use 3pin. what is differ 2pin 3pin????
2.I use cdc - 232 , easy , there are function to read 8bytes from usb and function to write 8bytes,
have any code for easy HID device with easy function (read write data).
I'm not expert for USB and don't want learn precise how this work.
I need any code for atmega168 and all other function implement self.
have some one easy HID project, just send 1byt for any port and read any port (one byt) that all.

regards

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Sat Oct 02, 2010 4:12 pm

dzairo wrote:I just have problem with real time reading and decoding RFID tag. but try use 20MHz crystal and try found position where can I disable - enable interrupt what I need for RFID.

The only practical way to do this would be to use a different interrupt for RFID, as your program must not use a higher priorty interrupt than that which is used buy v-usb. Enabling/disabling wont work beacause you cannot know when the host will send a request.
dzairo wrote:of course send me link to any easy HID device where can I send or receive data from to USB.
I look at it and try too.

If you could live without the ability to send text to the LCD, you could just emulate a usb keyboard to read data from the RFID. See the easylogger project http://www.obdev.at/products/vusb/easylogger.html Otherwise you would need to write dedicated PC software to communicate with your device. The HID-data project has example PC software for this.

Good luck.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Sat Oct 02, 2010 11:21 pm

dzairo wrote:I search on the web easy example for USB HID using.
But I don't find easy code.
question for all.
1. some code use only 2-avr pin some code use 3pin. what is differ 2pin 3pin????
2.I use cdc - 232 , easy , there are function to read 8bytes from usb and function to write 8bytes,
have any code for easy HID device with easy function (read write data).
I'm not expert for USB and don't want learn precise how this work.
I need any code for atmega168 and all other function implement self.
have some one easy HID project, just send 1byt for any port and read any port (one byt) that all.

If you must use CDC and the T0 interrupt then the best solution I can see for you is to employ another (tiny) MCU. It could be done one of two ways: Either keep your existing design and add a dedicated MCU for the CDC (ATtiny2313 might be a good choice here) or you could use a dedicated MCU to decode the RFID (ATtiny25 perhaps) USI to the main MCU doing the CDC & LCD work.

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Sun Oct 03, 2010 1:18 pm

Hey maxi.
I'm not expert for USB but why ??????
if enable interrupt for RFID (T0 interrupt is enable) and read RFID TAG on the real time still can send data from USB in to MCU , why Because INT0 has greater priority than T0 and all work good.
but if want send data from MCU in to USB then is problem and some problem found and halt some in function and then I can§t send any data from MCU in to USB ( must reset mcu).
why is different between send data from USB to MCU and read data from MCU to USB.
I think so if PC send data then MCU use INT0 and have bigger priority but if send MCU data into USB don't use any priority and then T0 ruin timing for send data and then I can't send any data.
But if I will know where start send data from mcu in to usb then I can disable interrupt T0 and if all finish then I can enable T0 interrupt.
this is my idea .
what about you???

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Sun Oct 03, 2010 2:41 pm

vusb.wikidot.com wrote:CDC requires bulk endpoints which are forbidden for low speed devices by the USB specification. However, most operating systems don't care and CDC works. There are still many drawbacks involved (see disadvantages below) and the main purpose of implementing this class is to simulate older devices which had a serial interface.

Advantages:

* Devices compatible to old serial gadgets can be built.
* Communication parameters (bit rate, parity etc.) can't be wrong because they are ignored.
* Host side programming interface is well known and understood by most hobbyists.

Disadvantages:

* Violates the standard.
* Does not work with some versions of Linux (in combination with particular USB host controllers).
* Consumes ca. 90% or more of the AVR's CPU time because bulk endpoints are polled aggressively by the host. Real-time applications on the AVR are close to impossible.
* May become unreliable if other interrupts are used on the AVR.
* Requires an INF file on Windows which binds the device to the CDC driver DLLs. These DLLs differ from Windows version to version.

Examples for this type of device: AVR-CDC and AVR-Doper.

Read in particular the disadvantages re interrupts!
Like I said earlier USB is host controlled, you cannot know when the host will send a request.

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Sun Oct 03, 2010 3:24 pm

I know but if host send request all is OK. IF T0 interrupt then all request from host I receive, no data lost . but problem only if user (own function want send data in to host.
sorry for my english is poor.
how mcu know so need to send data to host??? must set any data or bit and on this point need disable T0 interrupt . and if data are send and host send ack for MCU then can enable T0 interrupt .
or just every some time usb host send request for data are to send or data are to read???
If I connect my mcu in to JTAG - dW and debug then I can halt program (breakpoint )on some line and stay here some time then run and all work good, windows don't inform so device is disconnect or some think else. if USB host send request on some time , like every 100ms or less then I lost communication PC USB - MCU, but not . all work good.
only if want send data from MCU in to host , there is problem .
INT0 have higher priority like T0 and then if receive request from host It does not matter if exist other interrupt or not (only interrupt with higher priority can halt this).

may I don't understand USB but on my PC it work.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Help with USB ...

Post by maxi » Sun Oct 03, 2010 3:51 pm

Given that you are using INT0 for vusb I guess it should work atleast some of the time, even if unreliably. Perhaps if you show the code where you send the data, someone might be able to see where you are going wrong.

dzairo
Rank 1
Rank 1
Posts: 35
Joined: Wed Sep 22, 2010 3:31 pm

Re: Help with USB ...

Post by dzairo » Sun Oct 03, 2010 4:04 pm

Hi maxi.
For this time I solve this problem with higher crystal.
I use 16Mhz and read RFID tag fast and don't need use in interrupt mode.
Now I must solve problem with read data from MCU in to host , still have some problem .
when make this trouble then post my code , if have more free time then make schematic and PCB board.


regards

Post Reply