PIC serial communication receiving programming problem

Status
Not open for further replies.

redsuns

Newbie level 2
Joined
Mar 16, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,294
hello, i am doing my project which is capturing image with a TTL camera and read from the EUSART of the microcontroller

i am stuck on the programming for how to read from the RCREG without any data lost

datasheet of camera

my original code is below but it will cause data lost

Code:
void camera_rx()
{
	int x;
   unsigned char rx_buffer[512];
	for(x=0 ; x<=512 ; x++)
	{
		RCSTAbits.CREN=1;
		while(PIR1bits.RCIF==0);
		RCSTAbits.CREN=0;
		rx_buffer[x]=RCREG;
	}
}

if i don't enable and disable CREN then it will cause overrun error and i don't have any other idea to solve both problem, this is very urgent and important to me, so can anyone help out on how to write the programming for storing 512 byte continuosly into an array ?

thanks
 

You need to have a circular buffer and two pointers, a read pointer and a write pointer.
You should use the receive interrupt to write the characters to the buffer and increment the write pinter, and your main program loop to read the data and increment the read pointer.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…