Thread: USB interface

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    16

    USB interface

    Hello, i am not shure if this is the wright topic for tech board.

    But i am looking for some info on how to program usb.
    is there any cind of chip or something that wuld make programming simple like printer port.

    Printer port gets data in 8bit block and you have to write a number 0 - 255 to port 0x378, and you can turn on some leds from pins i think 2 - 9.
    and this works wery good and is also easy, only problem is that you can flash only 8 led-s.

    I read on how stuf works that USB can send data in 64-bit block, so i think this culd mean 64 led-s, and if you hook up another device it can be 64 bits of upstream too.

    But usb has only 4 wires, and 2 of tham are for power supplay.

    that means you need a chip that 64 outputs and 4 inputs, i also read that the device like this needs to comunicate back to the computer so that it can know what it is.

    Does anyone have any good links, or forums, or books were i can find more info about this, couse google is very poor on info about usb.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    On most OSs USB devices appear as normal disk devices. Are you trying to implement a driver or something?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    USB is a serial protocol, so it uses only one[1] wire to transfer the data in each direction. Data is sent one bit at a time, so if you send 8 bits, the data is sent over 8 times the bitrate (e.g. 1.5Mbit/s -> 0.67 microseconds per bit, so one byte (8 bits) takes 5.33 microseconds to transfer at this speed).

    USB uses a "protocol" to indicate what it wants done and to where, so it's not sending data as simply as the parallel port or serial port on the PC, which just sends exactly the data you send to the respective port.

    USB has a packet format that acts as an "envelope" to hold the data.

    To make a 64-bit LED-array, you need a noticable amount of both software and hardware to implement the protocol and translate it into a 64-bit value. It would probably be easier to use a parallel port and some latches (using for example the upper 4 bits for "address" and the lower 4 bits for data - 16 addresses x 4 bits of data = 64 bits) - this can be done with a handfull of 74-series logic chips, or in a relatively simple FPGA type chip - USB implementation will require quite a lot more.

    [1] In USB, the data is actually transmitted on TWO data-lines at the same time, D+ and D-, and data goes in one direction at a time - It works like when you have road-works so that only one lane is available, the trafic-lights control which direction of traffic flows. Or a CB-radio, where the talker says "Over" to indicate that the other side can talk now - similarly, USB uses a protocol between the two ends to indicate which side "can talk now".

    --
    Mats

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    yes making 4 addres and 4 data bits on paralel port is ok, but if you want to controol more than 4 stepper motors it is not practical, couse each motor needs a step and direction ping, and on step ping you need to put the steps in very fast.

    so if i understand this corectly using usb port to controll more than 4 stepper motors is not so good idea?
    Or can i make a software together with hardware so that it wuld mimic a paralel port?
    i have no ide how much work this wuld need, i am a beginer in programming.
    Last edited by ziga; 08-21-2007 at 10:24 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    How do you think USB manages things like say cameras, scanners, flash drives, etc etc?

    There's a chip (and maybe another processor) at the other end of the wire which is able to understand the USB protocol and information that you send it.

    For example, for 64 motors, you could use a single byte.
    6 bits to address the motor
    1 bit for 1 step clockwise
    1 bit for 1 step anticlockwise


    I would suggest you get one of these, or something like it available at a store near you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    yes you can do it this way on paralle port too, but than you need a special curcit with some ram to store how motors must move, couse all the mottors must move at exactly the same time, for input were you check if the mottors did move as you orderd tham you need, difrent cind of comunication, couse you need to get information if the motor moved to much or to little so u can stop it. andd all this is happening very fast, and i am not sure if computer can keep up, so i am thinking that i need a very minimal number of chips.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It sounds like what you really need is a small microcontroller that can control 64 motors at the same time - you could then tell it what needs to be done by whatever interface the microcontroller supports - there are several on the market that does USB, as well as serial interface.

    --
    Mats

  9. #9
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    yes that is what i need, but i wanna control it wia usb, and a program wich i can write in c++ on debian, i wuld like to get some experience interfacing usb port

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The good thing is that the low-level USB interface is already there.

    You need to do some research in how to interface to a USB device from Linux - I have no experience in this, so I can't help. Try the web-site described above.

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. Calling IRichEditOle interface methods
    By Niara in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 01:23 PM
  3. USB camera interface using DirectShow
    By abachler in forum Windows Programming
    Replies: 1
    Last Post: 07-30-2007, 01:05 PM
  4. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM
  5. Printers On USB
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-10-2002, 11:48 AM