How to transfer data from a PC (via USB) into a Microcontroller's RAM

Discussion in 'Embedded Systems and Microcontrollers' started by qw10, Jan 22, 2012.

  1. qw10

    Thread Starter New Member

    Jan 22, 2012
    1
    0
    Hi all! This is my first thread here!!

    My question is simple.

    I need to transfer the content of a .wav file, which is currently in a PC computer, into the RAM of a PIC24xxx... (16-bit data bus) via USB.

    This .wav file is nothing else than a list of 16-bit numbers that represent a sampled audio.

    For example:

    Data 1: 1010 1011 1110 1000
    Data 2: 1110 1101 1100 1010
    Data 3: 1010 1001 1010 1001
    Data 4: 1100 1101 1000 0001
    .
    .
    .
    etc, etc

    So I need this group of numbers inside the RAM of the microcontroller (to eventually being able to play it back, as you can imagine).

    well, I know that there are microcontrollers that have a built-in USB capability and there are others that don't. Also I know that some people put a converter (USB to UART) to input data into the microcontroller in a (apparently) easier way.

    Questions:
    1) What do you people recommend me overall?
    2) What does a USB transmission consist of? Is it like a RS232 one? (start bit followed by data followed by parity bit followed by stop bit).
    3) Have you got anything similar to this implemented at all? Any assembly code or C programs to show me? Any schematics diagram?

    Thank you very much indeed.

    qw10

     
  2. Eric007

    Senior Member

    Aug 5, 2011
    1,044
    33
    Well, there must be other sophisticated method to transfer those data via USB or whatever...but I'm not sure how it actually works...

    I'll have to do something similar very soon...and I'll transfer those data manually into the RAM...use Matlab to get data point from that wav file and write a code to put those point into the RAM...

    There must be a better way of doing that but not sure how to do it...
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,179
    1,800
    A PIC24xxx is a pretty generic choice. It the part you select has some USB hardware on it, then the hardware design might not be that hard.

    The hard part will be coming up with enough firmware to enumerate the device correctly. Each time you enumerate incorrectly the PC will lock you out and you either have to clean the registry or change something in the PID/VID responses to the PC. Having a USB analyzer will also be helpful. The BEAGLE from TotalPhase @ USD 400.00 is recommended.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,019
    Does it have to be USB? RS232 is much more simple.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Microchip provides some really nice example programs for using the USB capability of their chips. While USB apps can become quite complicated there are several very useful and simple things you can do to jump start a task like this.

    There is an example project "Device - CDC - Serial Emulator" for the PIC24EP512GU810 in the current library. It looks like a serial device to any windows program but uses the USB to send the data.

    On the PIC side you can grab these characters and store them into your RAM. You can even write some control character code so you can start stop and verify the transfers.

    The USB code is a little tricky to reuse as you need to keep inside a tight mail loop, but that isn't all that hard. Just try to follow the sample code, see how ti works and find the right place to insert your custom code.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The 24F series do have limited RAM. The limit is 96Kb at most. Not much space for storing any sound. Can you elaborate on what you are trying to do. Without holding back any details. Perhaps it would be better to store the sound in the flash memory not the RAM.
     
  7. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    Eric007 likes this.
  8. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    Firstly, you have to get hold of the data on your PC. The data is either stored in a file on the PC or it is in a program such as Excel, VB, Labview or Matlab. You can use Hyperterm to send the data over a COM port. Or you can write a program in C, Excel, VB, Labview or Matlab to send the data over a COM port. If you do not have a COM port you can use a USB-to-RS232 adapter to make the USB look like a COM port.

    The next step is to connect the RS-232 cable to your MCU using a RS-232 transceiver.

    Then you write a program on to run on the MCU to receive the data using the SCI or UART.
     
Loading...