void rxstring() ////function which receives the string and then print it on serial monitor
{
char myValue;
while((UCSR0A & (1<<RXC0))==0);
{
for(int i=0;i<5;i++) ////here i<5 ....5 is the length of the string which i am sending
{ bit(UCSR0A); //// if i change i<10 .....then string of length 5
myValue = UART_RxChar();
str[i]=myValue;
UART_TxChar(str[i]);
printString("\n");
//bit(UCSR0A); //function to print the value of register in binary.
}
void bit(uint8_t val)
{
int8_t ptr;
for(ptr=8;ptr>0;--ptr)
{
if ((val >> (ptr-1)) & 0x01)
{
UART_TxChar('1');
}
else
{
UART_TxChar('0');
}
}
}
i have made the function rxstring() for printing the string on the serial monitor (the string is received by atmega328 from laptop and then wants to print that string on serial monitor).
now
1) when i dont write function bit() in rxstring() i get the output like in screenshot (119)( which is correct and prints all the characters of the string and stores the string in str).
but
2)when i write the function bit() in rxstring() i get the output like in sctreenshot(121)( which is not correct as characters of the string which i send are missing and it stores the incorrect string in str ...like the characters which are missed are not read or gets overwrite....i write the bit() to read the value of UCSRA register in binary so that can make out how the bits of it gets changed character by character and to see the value of it when the last character of the string is send).
but i cant make out the error and didnt understand the values which are shown by the register UCSRA according to the characters received.
also what is reason for characters not printing??
main function is this
int main(void)
{
UART_Init();
while (1)
{
rxstring();
printString(str);
printString("\n");
if(strcmp("kunal",str)==0)
printString("string found\n");
}
}