View previous topic :: View next topic |
Author |
Message |
Guest
|
Sending 2 bytes without waiting |
Posted: Thu Sep 24, 2009 11:28 am |
|
|
Hi,
I am using a PIC18F2520.
These lines of code are called every 250ms.
Code: | putc(OutByte1);
putc(OutByte2); |
I don't want the PIC sitting between these two statements waiting for the first one to complete. As I understand the datasheet TSR will be empty before the first putc.
The first putc will load the TXREG register with OutByte1, which will "instantly" move to TSR Register and allow OutByte2 to then load into TXREG. Effectively a one byte hardware buffer? How many cycles will these two lines take?
1 to load TXREG with OutByte1 (MOVFF command?)
1 to move TXREG to TSR
1 to load TXREG with OutByte2 (MOVFF command?)
In my case only two bytes are ever sent so I don't think I need to implement a TXIF interrupt?
I can't afford for a delay between these two putcs! |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Sep 24, 2009 12:25 pm |
|
|
Just use the interrupt. There is seldom, if any, reason not to.
Code: | C:\Program Files\PICC\Examples\EX_STISR.C |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 24, 2009 1:38 pm |
|
|
Quote: | In my case only two bytes are ever sent so I don't think I need to implement a TXIF interrupt? | Yes, in this special the direct method means less overhead. |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 24, 2009 2:49 pm |
|
|
Provided the hardware buffer is empty, and the shift register is empty, when you start, the two putc instructions won't wait.
The code used by CCS, tests the buffer full bit, and only waits when sending a character, if the hardware can't take it.
Best Wishes |
|
|
|