LPC2468. Writing to a file with fopen

Hi all,

I am working with LPC2468 board from embeddedartists using the IAR Embedded Workbench 7.3

I want to write my results read from a double variable into a txt file created on the PC. I read on the forums and already set the library settings to FULL to read the Dlib_Config files.

       #include        #include         #include                 FILE* file;        file = fopen("H:\test.txt","rw+");        fprintf(file,"%An",max_temperature_DegC);              fclose(file);  

I used this standard code. Although I have no compiler warning/errors. But when I debug; the code it gets stuck in the undefined handler (abort handler) as I can see it in the disassembly. The output file is not created and has no output. I am not using UART or any I2C to write to the file.

Is it possible to write to a file on a PC directly or one has to use UART/I2C

Thanks

--------------------------------------- Posted through

formatting link

Reply to
sns22
Loading thread data ...

Op Fri, 10 Apr 2015 13:54:41 +0200 schreef sns22 :

Note that "\t" is a tab character.

Easy solution: use semihosting. Probably impractically hard solution: use C-SPY macros. Definitely insanely hard solution: write a plug-in.

--
(Remove the obvious prefix to reply privately.) 
Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/
Reply to
Boudewijn Dijkstra

Imaging if you cold create a simple device connect it to any PC and being able to write or delete data on any PC without the PC having any control. This is what you are trying to do.

How do you think your LPC board can physically access data on your PC? You have to create some kind of "agent" on your PC that receives data and commands from your board via some kind of communication channel (i.e. UART) and does the real writing to files on the PC.

--
Reinhardt
Reply to
Reinhardt Behm

Hi Sns,

What kind of connection do you have to the board? As it was already mention ed, you have to have some kind of interface between the board and the pc. O f course the dev board is probably used with some kind of debugging interfa ce (JTAG probably, even if the physical connection on the board is USB), bu t of course the embedded system is designed with with standalone operation in mind as well. So if you want to keep the JTAG connection, you could use semihosting for this purpose. It works in a way that a minimal support for system functions is kept on the embedded system. Calls to this "system supp ort" layer result in an exception, which is caught by debugger (still remem ber that it's connected with JTAG). Debugger figures out what the system wa s trying to do and processes it on PC. This way you can open a file from PC and write to it - the write is processed by the PC. This obviously will only work with PC connected.

If you would like to write to a PC file without the JTAG, you need some kin d of agent on the PC. For example embedded board sends data over UART and o n pc there is an application that listens on UART and writes received data to a file. This seems like a simpler solution (I don't have experience with semihosting so maybe I'm overestimating the effort needed).

Btw. UART may be easier to use for PC communication. PCs don't have usually hw needed for I2C/SPI communication. USB also is a possibility, but it req uires more work on embedded side.

See:

formatting link
Op Fri, 10 Apr 2015 13:54:41 +0200 schreef sns22 :

t
Reply to
mikuslaw

Are you sure that you've specified the correct *library* (RTFM -- there are different library "flavors" depending on the sorts of support you expect from your debug host).

[Sorry, I'm traveling and can't provide an explicit pointer to *which* library you should be using...]

Also beware multithreading issues. E.g., I typically spawn processes with stderr mapped to the "console". This allows me to watch the progress of each process along the lines of: task1: initializing task1: awaiting producer task3: initializing task2: initializing task3: driver on-line task3: awaiting command task2: out of memory Note that each "fprintf(stderr, ...)" appears as an atomic operation; the characters from task1's fprintf(3c) are not interspersed among the characters of task2's fprintf(3c) invocations, etc. Likewise, task1 doesn't have to explicitly fopen(3c)/fclose(3c) the "console device" one-line-at-a-time (i.e., as if it was holding a lock for the duration of the fopen(3c).)

In production code, all of these function invocations just turn into (expensive) no-ops.

Reply to
Don Y

In article , sns}22 wrote: .. } file = fopen("H:\test.txt","rw+"); } fprintf(file,"%An",max_temperature_DegC); .. }I used this standard code. Although I have no compiler warning/errors. }But when I debug; the code it gets stuck in the undefined handler (abort }handler) as I can see it in the disassembly. The output file is not }created and has no output.

As someone has pointed out "\t" is a tab character. But a more important point is that your code is wrong because it does not check for fopen() failing. When you use any library function that is documented to report a failure, you should check that it succeeded and report if not. The error codes are there for a good reason. Maybe H: doesn't exist, or it's a physical drive with no medium, or the medium is write-protected, or the file name is illegal, or there's already a file of that name which you don't have permission to overwrite, or there is no space to create a new file, or ... lots of things.

Reply to
Charles Bryant

Hi

Sorry for late reply. Somehow I did not get an email notification for the a nswer. I have come back to the situation again.

Thanks I also figured out the SDcard possibility in the development board.

I am using UART to read the data from controller and I store it in a buffer . I can see this data on putty serial connection window. I am using JTAG fo r communication. And I have the PC connected via serial cable to the board. I am using the semi-hosting in IAR.

Now I just want to write to a file on the PC stored on the PC.

Thanks sns

Reply to
snehanidhi22

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.