samizard
Junior Member level 2
- Joined
- Oct 27, 2017
- Messages
- 23
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 198
char DataRdyUSART(void)
{
if(RCSTA2bits.OERR) //***
{
RCSTA2bits.CREN = 0; //***
RCSTA2bits.CREN = 1; //***
}
return PIR3bits.RC2IF;// .RCIF;//***
}
char response;
....
....
....
putrsUART("AT\r\n"); //sending on uart
getsUSART(response,20); //reading uart
void getsUSART(char *buffer, unsigned char len)
{
char i; // Length counter
unsigned char data;
for(i=0;i<len;i++) // Only retrieve len characters
{
while(!DataRdyUSART());// Wait for data to be received
data = getcUART(); // Get a character from the USART
// and save in the string
*buffer = data;
buffer++; // Increment the string pointer
}
}
BYTE ReadStringUART(BYTE *Dest, BYTE BufferLen)
{
BYTE c;
BYTE count = 0;
while(BufferLen--)
{
*Dest = '\0';
while(!DataRdyUART());
c = ReadUART();
if(c == '\r' || c == '\n')
break;
count++;
*Dest++ = c;
}
return count;
}
...is no useful description.it doesnt work.
Only interrupt. Even for high density arm processor even having DMA onboard we anyway needs to use interrupts when data is received. The only defference that with DMA you can read multiple bytes in a row, but the whole approach it similar.is there anyway to read rcreg without waiting for rcif to set..??
Not if you want to read a valid value - see Figure 21-6 of the MCUs datasheet to see why. Basically the RCxIF bit is set when a valid value is placed into the RCREGx register.is there anyway to read rcreg without waiting for rcif to set..??
You write to memory not owned by your program.Code:[COLOR="#FF0000"][SIZE=4]char response[/SIZE][/COLOR]; .... .... .... putrsUART("AT\r\n"); //sending on uart [COLOR="#FF0000"][SIZE=4]getsUSART(response,20);[/SIZE][/COLOR] //reading uart
heres the code for getsUSART:-
[/CODE]Code:void [COLOR="#FF0000"][SIZE=4]getsUSART(char *buffer, unsigned char len)[/SIZE][/COLOR] { char i; // Length counter unsigned char data; for(i=0;i<len;i++) // Only retrieve len characters { while(!DataRdyUSART());// Wait for data to be received data = getcUART(); // Get a character from the USART // and save in the string *buffer = data; buffer++; // Increment the string pointer } }
[COLOR="#FF0000"][SIZE=4]char response[21][/SIZE][/COLOR];
....
....
....
putrsUART("AT\r\n"); //sending on uart
[COLOR="#FF0000"][SIZE=4]getsUSART(response,20);[/SIZE][/COLOR] //reading uart
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?