Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple UART RX question

Status
Not open for further replies.

mikesmixes777

New Member
Hi,

I am using a PIC18F252. I can send data to hyperterminal successfully.

My question, where in your code do you "look" for data received? I'm using Asynchronous mode. I read that RCIF will be set when reception is complete and an interupt generated "IF" they are enabled. There is a way without using interupts...

DO i write a seperate routine to check for data received...if so how?

Any help will be appreciated.

Thanks :D

Code:
void init_usart(void)				
{
	TXSTA=0b00100100;			// Asynch,8bits,tx enb
	RCSTA=0b10010000;			// Cont receive enb		
	SPBRG=129;				// BaudRate=9600 @ 20Mhz as Table
	RCSTAbits.SPEN=1;			// Enable Serial Port
} 

void write_usart(unsigned char send_ch)				
{	
	TXREG = send_ch;
	while(TXSTAbits.TRMT==0);		// Wait for TX to finish
}
 
Thanks for the help. I managed to get the data without the interupt.

Thanks for the help
 
hey, when you set up the tx pin of the uart, did you set its direction as input or output? Some people on this forum have said it should be set as input, which i found a bit confusing. Thanks
 
You have to check the Data Sheet for the device you're using. You use different settings for different devices (unfortunately)...
 
I managed to get it working, thanks....

Apart from small code problems the one thing I hadn't enbled was RX as an input. TX must be set as an output for my PIC.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top