2011-07-22 06:10 AM
Hello,
I try to write what I receive into a .txt. First I do this: RCC_Configuration(); GPIO_Configuration(); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USARTy, &USART_InitStructure); USART_Cmd(USARTy, ENABLE); USART_SetPrescaler(USARTy, 0x1); USART_IrDAConfig(USARTy, USART_IrDAMode_Normal); USART_IrDACmd(USARTy, ENABLE); I think this is the good configuration (well sure...) then I send the command like this: USART_SendData(USART2, 'a'); then I have tried to do: int size= 128; for (i=0;i<size;i++) { buf[i]= USART_ReceiveData(USART2); fprintf(t1,''%c'',buf); } and I tried to use the USART_Scanf(128); but none of them runs. I don't know how to write into t1, all the text I receive. thanks to any help...2011-07-23 05:52 AM
fprintf(t1,''%c'',buf);
You'd want to ensure the string was NUL terminated, and be using sscanf(). I think you'd want to accumulate all the characters in buf[] before copying them to t1. What's the bounding condition, assuming you don't always receive 128 characters?2011-07-25 12:32 AM
hello,
thanks for replying. The number 128 is for the example. I don't know how long will be the answer. I have found for using sscanf() but this is for convert a string into an int. I don't understand how I should use it. Could you be a little more precise please? Thanks2011-07-25 02:59 AM
Have you created your .txt file?
Maybe it would be better if you put something like this at startup (if you haven't done this).
FILE * t1 = fopen( ''yourFile.txt'', ''w'');
2011-07-25 03:09 AM
Yes it exists. I have created it like you say.
This is not the solution :) thanks anyway2011-07-25 03:36 AM
Surely it would be easier to use
fputch(t1, buf[i]);2011-07-25 03:53 AM
t1 probably returns a NULL pointer. I think you may have to rewrite file creation and file writing functions yourself.
2011-07-25 06:37 AM
I don't know this function : fputch
What does it do? And for the files I create my file like this: FILE *t1 = NULL; t1 = fopen(''test1.txt'',''w''); fclose(t1); t1 = fopen(''test1.txt'',''r+''); I am still trying, and still no succeed. Thanks for your help2011-07-25 05:15 PM
Sorry I was confused by the use of fprintf, where buf is a pointer, not a char value, and it was always the pointer to the first character.
int size= 128; for (i=0;i<size;i++) { buf[i]= USART_ReceiveData(USART2); fprintf(t1,''%c'',buf); } Something like this would frankly make more sense in C int size= 128; for (i=0;i<size;i++) { fputc(USART_ReceiveData(USART2), t1); } Then again, all this presumes you have a file system to send the data too. Unless you have a file system, and a memory device driver of some sort, it usually makes more sense to store data to RAM or FLASH in a more direct fashion.2011-07-26 12:30 AM
At this moment I'm jsut trying to see if I succeed to send and receive data by Usart way (or UART). I just want to see if I can get the datas.
After I will write all the datas into the Flash memory, but at a moment I will write all the flash memory into a .txt. Thanks, I try what you tell me and I tell you if I fail or succeed...