hi to all,
i want to receive the string from the user in using UART communication...i have coded the below code but in this case the length of the string should be known to me .
But what if i want to take input from user and i dont know the length of the string ..in that case how should i do.not getting any thoughts ...so any suggestions or guidance how that can be done.
#include <uarts.h>
int main(void)
{ char buff[30];
UART_Init0();
//UART_Init3(); /* Initiate USART with 115200 baud rate */
//UART_Init1();
printString0("******************hellow*****************");
printString0("\n");
/* Start global interrupt */
while(1)
{
printString0("type a character \n");
char b=UART_RxChar0();
UART_TxChar0(b);
printString0("\n");
for(int i=0;i<10;i++)
{
buff[i]=UART_RxChar0();
UART_TxChar0(buff[i]);
}
printString0(buff);
printString0("\n");
}
}
function defination of the uart functions which i have used in above code
void UART_Init0()
{
UBRR0L = 103;
UCSR0B = (1<<TXEN0)|(1<<RXEN0);
UCSR0C = (1<<UCSZ00)|(1<<UCSZ01)|(1<<UPE0);
}void UART_TxChar0(uint16_t data)
{
while((UCSR0A & (1<<UDRE0))==0);
UDR0 = data;
}char UART_RxChar0()
{ //unsigned char status, resh, resl;
//status = UCSR0A;
//bit0(UCSR0A);
//printString0("\n");
while( !(UCSR0A & (1<<RXC0)));
//if ( status & (1<<DOR0)|(1<<UPE0)|(1<<FE0)==1)
//return -1;
//bit0(UCSR0A);
//printString0("\n");
return UDR0;
}char rxstring0()
{
char myValue;
while((UCSR0A & (1<<RXC0))==0);
myValue = UART_RxChar0();
return myValue;
}void printString0(char *myString) /////to print any string
{while (*myString)
{
UART_TxChar0(*myString++);
}
}