john blue
Advanced Member level 3
My UART keeps sending data out after a character is received. May I know how to do so that, when i send once, it will receive once without ussing interrupt if possible?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include <p18f4550.h> #include <usart.h> #include <delays.h> #include <uart.h> void main() { char data; char mybuff [] = "Hello"; char *ptr; char buff[100]; // ptr = RCREG; // point the pointer to buffer[0] OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 255); while(1) { data = getcUSART(); putcUSART( data ); } CloseUSART(); }
while(1)
{
if (DataRdyUSART())
{
data = getcUSART();
putcUSART( data );
}
}
getcUSART returns the character that's in the receive buffer without regard to whether it is a new character or not. You need to change your code to check if a NEW character is in the receive buffer. Something like this:
Code:while(1) { if (DataRdyUSART()) { data = getcUSART(); putcUSART( data ); } }