This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

data write to a file in the personal computer

Other Parts Discussed in Thread: MSP430FG4618

 Hi!

I am using IAR Embedded Workbench for MSP430FG4618. I want to write the data from

memory or I/O or ADC output to a datafile located in the Personal Computer. From the help

I understood that, first I need to open the data file. Example to open the file is given as:

__var filehandle;
filehandle=__openFile("Debug\\Exe\\test.tst","r"); /* For writing it should be w*/
if(filehandle)
{
 /*successful opening */
}

I declared:

int filehandle;

as __var is not accepted.

then in the main:

filehandle=__openFile("try1.dat","r");

At the time of build I am getting an error.

Please, help.

Best Regards

--Mala Mitra

  • What you attempted to do can be accomplished when the MSP430 is attached to FET tool under the control of IAR debugger. But it is accomplished with smoke and mirror. Once you exit the debugger, it stops working.

  • Mala Mitra said:
    __openFile("try1.dat","r");

    It is a common misunderstandign that one can use the full extent of the standard C library on an MSP.

    The MSP does not have an OS and no file system, so trying to open a file on an MSP makes no sense. Open a file on what storage device? Write the data where and how?

    There are some mechanisms to do it, but they are not as straightforward:

    IAR offers some fake file system support. AS OCY already said, it is smoke and mirror. The debugger hooks into some empty code (fopen/fwrite) and fethches the required ionformation (filename, data to write) from the MSP through the JTAG interface. It only works with this debugger and this specific version. New compiler/debugger version and you'll need at least to recompile the project.

    The 'normal' way to do it is to just output the data through a serial port, receive it on the PC side on a serial prot and capture it into a file. PUTTY, HyperTerm and similar programs can do it on the PC side, or you write your own PC client program. I foyu do so, you can add some additional functionality like passing the filename first, or compress the data to increase throughput. E.g. if oyu want to send 12 bit ADC data, you can pack 4 values into 6 bytes instead of 8 (4*12 bit =48 bit = 6 bytes) and the PC program extracts the 4 values before writing them to the file.

    YOu can, however, include a real filesystem driver into your MSP project. It requires some flash space and some buffer space in ram. Such an FS driver will offer you all fucntionality to open, write and read files on an unspecified storage device.
    You'll still need to write the transfer functions that read and write the raw data blocks (= 'disk' sectors), e.g. to and from an SD card.

  • Thanks a lot for your replies. If file support is not there why do we get so much in the documentation-- in the help files and the pdfs for IAR? Writing files in the PC definitely makes sense. Data is sent from the MSP430.  My students already did it with seriel port that you have suggested. In that case, we need to put an additional extrnal chip MAX233 to match with the TTL levels. I also did it with the help of emulator. But this is just giving one set of data. I think, I need to understand the trigger sequencer. File operation must be the easiest one. So I am  making an attempt.

    Best Regards

    --Mala Mitra.

  • Mala Mitra said:
    If file support is not there why do we get so much in the documentation-- in the help files and the pdfs for IAR?

    AS I said, IAR is providing a debugger-based backdoor mechanism. It requires the MSP to run under debugger control to work. It's a nice feature for debugging, but completely useless for any standalone application.
    I guess, the IAR staff is so proud of their smart tool that they post its presence everywhere and totally ignore the fact that it is of no meaning for any final product (except you want to pair a copy of IAR and a  FET together with every device you build)

    Mala Mitra said:
    My students already did it with seriel port that you have suggested. In that case, we need to put an additional extrnal chip MAX233 to match with the TTL levels.

    Yes. An alternative is to use an USB chip that directly converts TTL based serial input to an USB connection - the PC driver will provide a virtual serial port then. The USB FETs from Ti work this way too, teh standalone FETs as well as the programming parts on the experimenter boards liek the LaunchPad.

    In theory, you can set up the MSP to support an IDE harddrive and directly access its file system. But that's a major task.
    There are FAT filesystem drivers availabel for th eMSP. They convert all file operation fucntions that are normally available in C to simple block read/write operations. Where to read the blocks from wor write them to is still your job to implement.

    So I think, the easiest way is still  to go for the serial port and implement all higher-level stuff into the data protocol between the MSP and the (specifically written) PC application.
    The 'kings's way', however, would be to attach an SD card to the MSP and then read the data later on the PC.
    I've done it soem time ago, but I skipped the file systme part and just wrote raw data to the SD card (the memory address where the data was stored was derived from the time it was written). It required low-level access ot the SD card ont he PC later, but saved me the hassle of including a file system driver on the MSP.

  • You might take a look at the EZ430-RF2500 (http://focus.ti.com/docs/toolsw/folders/print/ez430-rf2500.html) and similar devices.  These are relatively cheap and have a back door 9600 baud virtual com port built in.  Perfect for doing the UART thing as per JMG without needing to manage the extra components.  In this manner, you can still run the communications when running your system stand alone.

    Jim Noxon

**Attention** This is a public forum