cancel
Showing results for 
Search instead for 
Did you mean: 

using fprintf problem

aeolia_amha
Associate II
Posted on June 18, 2010 at 09:15

using fprintf problem

11 REPLIES 11
Posted on May 17, 2011 at 13:55

This is an embedded system, you do not have a file system.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aeolia_amha
Associate II
Posted on May 17, 2011 at 13:55

I send the file via usart to a PC and I want to save it so that it is readily available to access. I think without using FLASH memory, RAM or EEPROM is more efficient since I can send it freely using USART and the PC user can easily access it for their application. How can you save the data being transferred. Can it be programmed within the MCU to automatically create a file and save it after transferring and a certain condition is met.

Any suggestions?

Posted on May 17, 2011 at 13:55

It is going to be hard to automate unless you write the application on the PC side.

As for passing a name from the embedded device to the PC via serial, YModem and ZModem spring to mind, or a custom protocol you design.

If you want to get a TCP/IP connection to the embedded device via a serial connection, a SLIP/PPP protocol would be workable and you could use TFTP, FTP, HTTP, NTP, etc to move data and time.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 13:55

''This is an embedded system, you do not have a file system.''

To be precise, you do not have a file systems unless you specifically implement one.

There are plenty of file system implementations available for use on embedded systems - the ST samples illutrating SD Cards and USB sticks have examples...

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:55

I haven't tried any example applications using file systems like USB. If I used the PC to send data like time, what should I include in the code to allow me to access the file and where to put the data into the MCU

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:55

Sorry for not clarifying, this is what I want to do, I  need to get the PC clock via usart and use RTCsetcounter=PCclock. After, I need to save the Time and voltage in the sensors per second for a span of a minute or so.

For now, I can only transmit time and 5 ADC values via usart and display them in hyperterminal. I can also set time manually by using USART_Scanf where it can only type numbers.

Here's my configuration code:

main()

{

while(1)

{

Timeshow();

}

/*******************************************************************************

* Function Name : Time_Regulate

* Description : Returns the time entered by user, using Hyperterminal.

* return : Current time RTC counter value

*******************************************************************************/

u32 Time_Regulate(void)    //input time

{

struct tm t;

time_t t_of_day;

printf(''\nYear:'');

t.tm_year = USART_Scanf(2038)-1900;

printf(''\nMonth:'');

t.tm_mon = USART_Scanf(12)-1; //Number of months since January. [0-11] Go figure.

printf(''\nDay:'');

t.tm_mday = USART_Scanf(31);

printf(''\nHour:'');

t.tm_hour = USART_Scanf(24);

printf(''\nMinutes:'');

t.tm_min = USART_Scanf(60);

printf(''\nSeconds:'');

t.tm_sec = USART_Scanf(60);

t.tm_isdst = 0;

t_of_day = mktime(&t);

printf(''\n'');

printf(ctime(&t_of_day));

printf(''tday = %d'',t_of_day);

//printf(''time(0)=%d'',time(0));

return(t_of_day); //Return the value to store in RTC counter register

}

/*******************************************************************************

* Function Name  : Time_Adjust

* Description    : Adjusts time.

*******************************************************************************/

void Time_Adjust(void)

{

  RTC_WaitForLastTask();       /* Wait until last write operation on RTC registers has finished */

  RTC_SetCounter(Time_Regulate());   /* Change the current time */

  RTC_WaitForLastTask();   

/*******************************************************************************

* Function Name  : Time_Display

* Description    : Displays the current time.

* Input          : - TimeVar: RTC counter value.

*******************************************************************************/

void Time_Display(u32 TimeVar)       //displays time and status of each sensors

{

  u32 THH = 0, TMM = 0, TSS = 0; //a2;

  double Vref=3.3;

  #define pi 3.1415926535897932384626433832795028841971

Vred = (double)ADC_RegularConvertedValueTab[6]* (Vref / 4096.0);

Vblue = (double)ADC_RegularConvertedValueTab[7]* (Vref / 4096.0);

Vgreen = (double)ADC_RegularConvertedValueTab[8]* (Vref / 4096.0);

Vyellow = (double)ADC_RegularConvertedValueTab[9]* (Vref / 4096.0);

Vorange = (double)ADC_RegularConvertedValueTab[10]* (Vref / 4096.0);

Vhumid = (double)ADC_RegularConvertedValueTab[0]* (Vref / 4096.0);

Vsum = (double)ADC_RegularConvertedValueTab[1]* (Vref / 4096.0);

  THH =(TimeVar%86400)/3600;    // Compute  hours  //timevar%3600 / 1440

  TMM = (TimeVar % 3600)/60;     // Compute minutes

  TSS = (TimeVar % 3600)% 60;      // Compute seconds

  printf(''\n\rTime: %0.2d:%0.2d:%0.2d\r'',THH, TMM, TSS);

  printf(''\n\rred=%0.2f blue=%0.2f green=%0.2f \n\ryellow=%0.2f orange=%0.2f'',Vred,Vblue,Vgreen,Vyellow,Vorange);

/*******************************************************************************

* Function Name  : Time_Show

* Description    : Shows the current time (HH:MM:SS) on the Hyperterminal.

******************************************************************************/

void Time_Show(void)

  /* Infinite loop */

 // while (1)  {

     if(TimeDisplay == 1){

      Time_Display(RTC_GetCounter());

           /* Display current time */

      TimeDisplay = 0;

    }

}

Posted on May 17, 2011 at 13:55

''If I used the PC...''

When you write a PC application, you abviously need to consult the documentation for the specific PC tools that you use!

 

If you make us of stuff like Windows or Linux APIs, then you will also, obviously, have to consult the approriate API documentation.

''...access the file...''

 

What file?? 

''where to put the data into the MCU''

Put it wherever is appropriate to the MCU application!

Or, are you asking what interface to use for transferring the data between PC & MCU?

Answering that question obviouslt depends on what interfaces are available, what data is to be transferred, etc,...

Posted on May 17, 2011 at 13:55

''I  need to get the PC clock''

 

Read the documentation for your PC tools to find how to do that.

Once you've found out how to obtain the time value, have the PC convert it into a format that the microcontroller can use directly to set its RTC

(remember that a PC is far more powerful, and PC tools are far richer and have far more facilities at their disposal - so it is always best to get the PC to do as much of the work as possible).

''via usart''

 

At the PC end, it's simply a matter of sending data to the COM Port - you PC tool documentation will tell you how to do that.

The PC doesn't need to know anything about the microcontroller; it just transmits the data in the specified format - it is irrelevant to the PC where the data actually goes to once it leaves the serial port...

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:55

I can get the PC clock and date automatically using a program like C#, I can send it to the MCU, I plan to send the clock in the Unix time format, the elapsed seconds after January 1, 1970. My problem is, what code should I use to receive the data. Can I use scanf, I think not because scanf deals with user typing the input and the input is one at a time, concerning number 0 to 9.