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-26 12:48 AM
with what you gave me, I actually have only a sequence of ''enter''.
If size is bigger then I have more enter. I can't see letters... I have also tried with USART_Scanf(), but I think is won't help me. I put you the function but it is only for getting a numerice value from hyperterminal. Maybe we can use a part of it.../**
* @brief Gets numeric values from the hyperterminal.
* @param None
* @retval None
*/
uint8_t USART_Scanf(uint32_t value)
{
uint32_t index = 0;
uint32_t tmp[2] = {0, 0};
while (index < 2)
{
/* Loop until RXNE = 1 */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_RXNE) == RESET)
{}
tmp[index++] = (USART_ReceiveData(EVAL_COM1));
if ((tmp[index - 1] < 0x30) || (tmp[index - 1] > 0x39))
{
printf(''\n\rPlease enter valid number between 0 and 9'');
index--;
}
}
/* Calculate the Corresponding value */
index = (tmp[1] - 0x30) + ((tmp[0] - 0x30) * 10);
/* Checks */
if (index > value)
{
printf(''\n\rPlease enter valid number between 0 and %d'', value);
return 0xFF;
}
return index;
}
2011-07-26 05:08 AM
Are you still trying to put all your received data on a .txt file?
clive1 has already stated that you need a file system and a driver to do that.
If you only want to check if you have received your input correctly, just implement a data loop-back.
maybe something like this:
while(1)
{
c = USART_ReceiveData(USART2);
printf(''%c\n'',c);
}
2011-07-26 08:00 AM
ok the answer is:
for (i=0;i<100;i++) { while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) { } fprintf(t1,''%c'',USART_ReceiveData(USART2)); } The RXNE has to be full before sending a data (1 bytes). If not the receive data is not a letter or a space etc. But now I have another problem... it stops before the end of the transfert. Always at the same time. And then it is stuck into USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET which keep into his state. I think that the register is full It stop to store the bytes. Or something like this. Is anyone have the real reason? And how to solve it? Thanks to everyone2011-07-26 08:02 AM
I'm still not sure where you think the .TXT file is going to be stored.
The following will input data into a buffer, 128 characters. It will then output this to the console, which could be the serial port if you have the stdio functionality suitably hosted. char buf[129]; int size= 128; for (i=0;i<size;i++) { while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); buf[i]= USART_ReceiveData(USART2); } buf[i] = 0; // NUL terminate puts(buf); // print to console2011-07-28 12:24 AM
Hello,
Your method doesn't work. I have try and it write something not good. I don't have a console, so I don't understand how I could check if it works... My only way to see if it works is to write it into a .txt (which works). But as I said, after a time it stop to write. At a certain time it goes stuck because of the state of the flag.2011-07-28 05:00 AM
Well that's unfortunate, you seem to be in a lot of trouble.
Are you using a real part or a simulation? What tool chain?2011-07-28 05:49 AM
I have IAR embedded workbench.
And there is no console like in visual studio. But if it runs, it runs !2011-08-01 02:25 AM
I want to try something but I don't know how...
I want to put as parameter into my while loop a ''end of transmission''. I want to stop the while when the last caracter is send. What is the function? Thanks2011-08-01 02:53 AM
last character (sorry)
2011-08-01 08:33 AM
You could spin on USART_FLAG_TC (Transmission Complete)