PDA

View Full Version : USART question?



starwick
- 26th May 2011, 12:54
If <code class="vb plain">PIR1.5 = 1 </code><code class="vb keyword">Then</code> <code class="vb comments">' If receive flag then...</code>
<table><tbody><tr><td class="number"><code></code></td><td class="content"><code class="vb plain">B1 = RCREG </code><code class="vb comments">' Get received character to B1</code></td></tr></tbody></table>
<table><tbody><tr><td class="number"><code></code></td><td class="content"><code class="spaces"> </code><code class="vb keyword">Endif</code>
<code class="vb keyword"></code>
<code class="vb keyword">The above code is from melabs sample programs.</code>
<code class="vb keyword">does PIR1.5 clear automatically after B1=RCREG? It's read only???</code>
<code class="vb keyword"></code>
<code class="vb keyword">The way i understand the above code is that PIR1.5 will go high when a validte data is rec'd in RX but how does PIR1.5 clear is it after reading the RC register?</code>
</td></tr></tbody></table>

dhouston
- 26th May 2011, 13:54
This is a case where reading the datasheet for your PIC will answer your question.

But, the answer is that this bit is cleared after reception is complete.

starwick
- 27th May 2011, 10:27
Thanks for the reply.
Here is a segment from 16F887 datasheet:





12.1.2.3 Receive Interrupt




The RCIF interrupt flag bit of the PIR1 register is set twhenever the EUSART receiver is enabled and there is
an unread character in the receive FIFO. The RCIF
interrupt flag bit is read-only, it cannot be set or cleared by software.
RCIF interrupts are enabled by setting all of the
following bits:
• RCIE interrupt enable bit of the PIE1 register
• PEIE peripheral interrupt enable bit of the INTCON register
• GIE global interrupt enable bit of the INTCON register
The RCIF interrupt flag bit will be set when there is an
unread character in the FIFO, regardless of the state of
interrupt enable bits.






















so as long as there is unread data in there the PIR1 will be set and stay set untill the read instruction is executed NOT when recving is completed as you mentioned. I might be wrong but this is how i understand it, Correct me if i'm wrong.

Thanks
,Best regards

dhouston
- 27th May 2011, 11:29
The italicized phrase in my first response was quoted verbatim from the 16F88 datasheet. By reception, I think they meant after the transfer to your variable - perhaps, a poor choice of terminology by Microchip.

There may be differences in the details between chips which is why consulting the datasheet (or consulting Darrell ;)) is the only way to deal with things like this.