How to Interface a USB Mass Storage Device with a PIC Microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by jobycm, Jan 7, 2015.

  1. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    Hi,

    I wanted to interface a USB storage device to PIC controller in order for data logging purpose. I want to write the log data as a text file to the pen drive. Should i use a PIC controller with USB support or a normal one.
    Even if i am using a PIC with USB support, i read that interfacing a mass storage device with it is not easy as they lack OTG capability.

    I only have a mere idea on this, please do help me.
     
    RRITESH KAKKAR likes this.
  2. mitko89

    Member

    Sep 20, 2012
    123
    19
    Hey,
    Yes, interfacing a uC to a mass storage device is not easy. If your purpose is merely to have a non-volatile memery for logging, I suggest considering uSD card. It will be much more efficient.
     
  3. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    you need OTG / USB host capability
     
  4. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    thank you guys..
    But i want to interface with pen drive itself.
     
  5. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    If i get the driver program for USB device is it possible to interface it with a normal PIC controller??
    Or interfacing could be done only with a USB supportable device like pic18f2550
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You need a controller with USB host capabilities.

    Not just a USB device controller.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    I've used a PIC32 as a host for a keyboard using library support files. PIC32's do support hosting on their USB ports.

    On several other projects I've used an SD card as a mass storage device while adapting library projects for a USB to SD card mass storage device as the base of the project. Then either a PC or the PIC can access the SD card. It all fell together rather nicely, though this was with the previous libraries using C18 or C32 compilers. I am unsure how to do it with the current generation of sample projects and the XC compiler.
     
  8. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    Is there any controller in PIC18 series which has USB host capability???
    I have another doubt, if we write a driver program for normal USB device controller, can it be used for my application(USB host capability)??
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    1. No.
    2. No.

    For instance the USB Host must enumerate through devices present.
    It could be seen like it is easy, but often theres a Host controller with more than one port.

    The USB device just takes part in the enumeration by the host. Its completely different code.
     
  10. MagicMatt

    Member

    Sep 30, 2013
    117
    14
    For all that hassle, wouldn't it be cheaper to get something like a Raspberry Pi and use it as a data logger, then just feed your data out of the PIC using a serial interface to the Pi - the Pi can then put it on screen, save to disk, email it to you, whatever!
     
  11. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    I think PIC24FJ64GB002 will be suitable for my project.
    But i have many doubts regarding the same,
    First of all, my data logging circuity comprise of An external EEPROM IC(24AA1024) and an RTC(DS1307). And the circuit is working at 5V logic,
    now if i replace my 8 bit PIC with PIC24FJ64GB002 there may be some problems, as its having 3.3V logic.My EEPROM & RTC interface is via I2C, so when these two ICs are still at logic 5V and PIC with logic 3.3V is there any possibility for failure in I2C comm.
    To which voltage i should keep the pullup for SCL and SDA lines of i2c?? should i keep the pull up to 5V or 3.3V??
    Please do reply..
    In PIC24FJ64GB002 datasheet i saw, its digital input pins are 5V tolerable(please tell me if it matters to i2c lines).
     
  12. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    Please find my existing circuit.
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    The EEPROM and the RTC need the I2C pulled up to 5V. The PIC needs it pulled up to 3.3V.

    If you intend to have these devices on the same bus you need an I2C level translator.

    I would have to declare the DS1307 "not recommended for new designs." Devices such as Phillips the PCF2129A have the crystal built into the device and are easier to use and far more accurate. Maxim makes a similar device but it is very overpriced.
     
  14. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You should consider serial FLASH it can hold more data. Also SD card isnt difficult. USB Host is very advanced, I havent tried it yet.

    Mixing 3v/5v isnt so good, its possible but you need to study the datasheet carefully. EEPROMs can work at 3 volts, and so can the DS1307.
     
  15. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Its easy to use? Actually I dont read out the time so often, instead I use the test signal, and only synchronize sometimes. When you use I2C you should always use a checksum, or see if the data makes sense, and program a timeout. Remove the chip, and test what happens. Your LCD etc. should display "I2C device removed" or something.

    Loop back if you wrote with I2C.
     
  16. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    I agree with the others, use an SD Card. You can get a USB SD Card reader that looks like a USB pen drive with a slot for the SD Card which may avoid you needing to interface your PIC to USB storage.
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    The Phillips RTC is as easy to use as any other I2C RTC, though it may store the information in a different format then you are used to. It also has an SPI interface if that is useful to you.

    It is ideal for occasional time refresh over the very long haul. 1ppm stability corresponds to about 31.5 seconds a year, this has an average stability of 3ppm, 5 ppm max, and long term (1o year) aging stability of 10ppm.

    Worst case, that is under 8 minutes over 10 years. Your backup battery isn't going to last that long.
     
  18. andye456

    New Member

    Mar 8, 2013
    5
    1
    I would use a Raspberry Pi - they are so versatile for this type of thing - only down side is that they are a bit OTT for most small embedded systems and use a lot more power.
     
  19. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    thank you guys..
    I have made a proto board using PIC24FJ64GB002, but i think i am still stuck with its USB pogramming.
    I am using CCS PIC C compiler and have done basic programming on this new chip like UART,
    but about writing a text file into the USB flash drive, i don't know, i am still blank.
    please do help.
     
  20. jobycm

    Thread Starter New Member

    Nov 17, 2011
    22
    3
    I have picked an I2C voltage translator TCA9406 for the interfacing purpose and i think its ok.
     
Loading...