|
|
View previous topic :: View next topic |
Author |
Message |
jeremiah
Joined: 20 Jul 2010 Posts: 1346
|
How does DISABLE_INTS interact with rs232 routines? |
Posted: Thu Nov 03, 2011 9:01 am |
|
|
This is probably a simple question, but is the DISABLE_INTS option supposed to do anything if FORCE_SW is not enabled?
Looking at LST files indicates not, but wanted to make sure.
As a followup to this, what does the ERRORS option actually do? Looking at the asm, I don't see any differences with it specified and without. The rs232_errors variable is still created regardless, and I all I see the assembly doing to it is copying the UxSTA register to it every time a getc() is called. Does that do something in particular?
I am using 4.124 if that helps.
sample code:
Code: |
#case
//Include file that comes with the compiler
#include <24FJ256GA106.h>
//16 bit pointers
#device *=16
#FUSES NOWDT //Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WDT32 //Watch Dog Timer PreScalar 1:32 - 1ms
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO //Internal External Switch Over mode enabled
#FUSES PR //Pimary oscillator enabled
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS
// #use statements for delays
#use delay(clock=22118400)
//Make sure to enable ERRORS in the #use rs232() call
//Also use a stream (for the printf section only)
#pin_select U1TX = PIN_B15
#pin_select U1RX = PIN_B14
#use rs232(UART1,baud=9600,parity=N,bits=8,DISABLE_INTS)
#INT_TIMER1
void timer1_isr(){
putc('i');
}
void main(void){
unsigned char rcv = "";
setup_wdt(WDT_OFF);
setup_timer1(TMR_EXTERNAL|TMR_DIV_BY_1,0x8000); //every 1 second
setup_timer2(TMR_DISABLED);
setup_timer3(TMR_DISABLED);
setup_timer4(TMR_DISABLED);
setup_timer5(TMR_DISABLED);
setup_adc(ADC_OFF);
setup_vref(VREF_DISABLED);
enable_interrupts(INT_TIMER1);
enable_interrupts(INTR_GLOBAL);
//Give time for devices to power up.
delay_ms(2000);
putc('m');
rcv = getc();
while(TRUE);
}
|
getc() LST section
Code: |
.................... #pin_select U1TX = PIN_B15
.................... #pin_select U1RX = PIN_B14
.................... #use rs232(UART1,baud=9600,parity=N,bits=8,DISABLE_INTS)
00244: BTSS.B 222.0
00246: BRA 244
00248: PUSH 222
0024A: POP 800
0024C: MOV 226,W0
0024E: BCLR.B 222.1
00250: RETURN
|
800 is rs232_errors according to the SYM file, but I never specified ERRORS in my #use rs232 statement, and even if I do, it doesn't seem to change the LST file that I can tell.
EDIT:
As something to compare, here is getc() when ERRORS is added to the #use rs232 directive:
Code: |
.................... #pin_select U1TX = PIN_B15
.................... #pin_select U1RX = PIN_B14
.................... #use rs232(UART1,baud=9600,parity=N,bits=8,DISABLE_INTS,ERRORS)
00244: BTSS.B 222.0
00246: BRA 244
00248: PUSH 222
0024A: POP 800
0024C: MOV 226,W0
0024E: BCLR.B 222.1
00250: RETURN
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 03, 2011 11:50 am |
|
|
I don't have the PCD compiler, so I tested this with PCH and an 18F452
and vs. 4.125. I got the following results.
These two lines both generate the ERRORS code:
Code: |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, DISABLE_INTS)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
|
That's for a hardware UART. I don't know why they have DISABLE_INTS
producing the ERRORS code. It's probably a mistake.
If you do a software UART, as shown below, the DISABLE_INTS will
cause the compiler to insert a few lines before and after the software
UART code. These lines read and save INTCON, and they disable the GIE
bit. Then after the software UART byte is sent, they re-enable GIE if it
was enabled upon entry to the software UART code. This is done for
both the transmit and receive code.
Code: |
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0, DISABLE_INTS) |
If you put in ERRORS with a software UART, the compiler ignores it and
doesn't generate any code. This is the correct behavior.
Code: | #use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0, ERRORS) |
So the only thing weird that I saw was that using DISABLE_INTS with a
hardware UART caused the generation of the ERRORS code. I don't think
it should do that. But normally you wouldn't specify DISABLE_INTS for
a hardware UART so it's not really a problem, though CCS should be told
about it. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1346
|
|
Posted: Thu Nov 03, 2011 12:46 pm |
|
|
Thanks!
As a followup, what exactly does the ERRORS code do that is needed? From the LST file, all I see it do is copy the UxSTA register into rs232_errors each time a read is performed.
I've seen it mentioned here that it prevents lockups, so I am guessing that reading the UxSTA registers resets something in hardware??? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Nov 03, 2011 1:04 pm |
|
|
As the PIC24 family manual clarifies, the overun error bit OERR has to be cleared in software to reenable receiption.
The shown getc() routine does two things
- copy UxSTA to the error variable, has no further effect
- reset OERR unconditionally: BCLR.B 222.1 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|