Reply by demolitron May 4, 20092009-05-04
So, to clarify the situation...

The terminal, PC, sends a string of characters to the PIC. The PIC echos the data back?

If that is the case then are you implementing any kind of flow control or buffering? Meaning this; If the terminal is sending the string its going to send it one character after another, without pause. Does your code use the Receiver Interrupt to load the data into a buffer?

I assume you have verified via ICD or something that the string income_data really does contain a faithful copy of the received bytes? I always try to take the simplest solution to the problem and verify it is not the cause, no matter how sure I am it isn't.

I would also code my stuff a bit differently (don't we all)...this is for a polled TX scheme.
void PrintBuffer(char *income_data)
{
while(*income_data) //Keep going till we see a null
{
TXREG=*income_data; //Load TXREG
while(!TRMT); //Wait until TSR is empty
income_data++; //Advance to the next character
}
}
Here is an interrupt driven one. Just set the pointer *income_data to the start of a null terminated string and kick off the TX.

interrupt void ISR(void)
{
if (*income_data) { TXREG=*income_data; income_data++; }
PIR1bits.TXIF=0;
}

--- In p..., "musabbirmajeed" wrote:
>
> Hi all,
>
> I am using 16 bit PIC18F2420 microcontroller with a single USART port. I am using MPLAB C18 compiler. I was trying to achieve duplex communication on a microcontroller with a single usart. I am using external interrupts for that purpose. All was well until now.
>
> The main problem is that when I send a string or array of characters to the pic, the computer on the other corner receives every alternate character i.e. it misses every alternate character.
>
> But, I am definitely sure that the whole string is coming into the RCREG register (I have debugged it). But, when the characters are placed in TXREG from RAM, they get lost somewhere until they reach the pc.
>
> I have also made sure that the baud rates of USART and both the pcs matches up. I have been trying to debug this circuit for the past one week, with literally no success. I would be really grateful to you if you can give me any suggestion or if any of you have ever faced this kind of problem
>
> My transmit code is as follows:
>
> while (i < strlen(income_data)) {
> //char *income_data;
> TXREG = income_data;
> while(PIR1bits.TXIF == 0);
> //putcUSART(income_data[i++]);
> //back = 0;
> i++;
> }
>
> PS: income_data contained all the character I sent on RX pin.
> Thank you for your consideration. Hope to hear from you soon.
> Best Regards,
> Musabbir Abdul Majeed
>

Reply by musabbirmajeed May 1, 20092009-05-01
Hi all,

I am using 16 bit PIC18F2420 microcontroller with a single USART port. I am using MPLAB C18 compiler. I was trying to achieve duplex communication on a microcontroller with a single usart. I am using external interrupts for that purpose. All was well until now.

The main problem is that when I send a string or array of characters to the pic, the computer on the other corner receives every alternate character i.e. it misses every alternate character.

But, I am definitely sure that the whole string is coming into the RCREG register (I have debugged it). But, when the characters are placed in TXREG from RAM, they get lost somewhere until they reach the pc.

I have also made sure that the baud rates of USART and both the pcs matches up. I have been trying to debug this circuit for the past one week, with literally no success. I would be really grateful to you if you can give me any suggestion or if any of you have ever faced this kind of problem

My transmit code is as follows:

while (i < strlen(income_data)) {
//char *income_data;
TXREG = income_data;
while(PIR1bits.TXIF == 0);
//putcUSART(income_data[i++]);
//back = 0;
i++;
}

PS: income_data contained all the character I sent on RX pin.
Thank you for your consideration. Hope to hear from you soon.
Best Regards,
Musabbir Abdul Majeed