Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Defining in-function Local Variables RS485

Status
Not open for further replies.
Because it also happens in another place, too, I thought it is no more necessary to attach the function itself. I am attaching it below:

Code:
int1 IsRecordOnCurFloor()
{
	int8 temp;
	temp = recordsIn;
	if(recordsIn != 0) {
		if(!b_duplicateCounterPreventFlag3) {
			invalidDataCounter2+=10;
			WriteEeprom(invalidDataCtr2E2, invalidDataCounter2);
			b_duplicateCounterPreventFlag3 = 1;
		}
	}
	else {
		b_duplicateCounterPreventFlag3 = 0;
	}

	if(temp &= ~floorControl[currentPosition]) {
		return 1;                                       // Şu anki kata kayıt var
	}
	else {
		return 0;                                       // Şu anki kata kayıt yok
	}
}
And as a note:
Code:
void WriteEeprom(int8 adr, int8 data)
{
    disable_interrupts(GLOBAL);
    write_eeprom(adr, data);
    enable_interrupts(GLOBAL);
}
Some unnecessary codes are also available in it, written to test.
Anyway, I have just started a test by commenting the following lines, will see what will happen:
Code:
#device HIGH_INTS = TRUE
disable_interrupts(GLOBAL);
enable_interrupts(GLOBAL);
By the way, what is the problem with the "enable_interrupts(GLOBAL);" in the interrupt routine?
 

Hi,

By the way, what is the problem with the "enable_interrupts(GLOBAL);" in the interrupt routine?

Usually interrupts are disabled automatically during an ISR.
So "disabling Interrrupts" is useless.
But "enabling interrupts" causes other pending interrups to be processed... immediately...before the actual ISR is finished. This may create problems with variables, stack, ...

Read about "nested interrupts"

Klaus
 
  • Like
Reactions: apsua

    apsua

    Points: 2
    Helpful Answer Positive Rating
Hello,
After the last changes (disabling the enable_interrupts(GLOBAL) and #device HIGH_INTS = TRUE), the tests are running without problem. The issue seems to be solved, thank you very much. I want to ask one more question. Should I disable_interrupts(GLOBAL) while sending data by rs485? The library disables only int_rda, but I am also using the timer interrupt.
Thanks again.
 

Hi,

I see no need for disabling the interrupts during UART operations.

Generally ... why one disables interrupts:
* either, if you expect an ISR to change data you are just processing.and you don't want this
* or you have a timing critical process, where you don't want to be interrupted.
Else don't disable the interrupts.

You should always be aware of
* what variables are use in an ISR
* how often an ISR is executed
* and how much time an ISR needs ( here i often use one port pin switched HIGH at the beginning of an ISR, and switched LOW at the end of an ISR. Measure time with a scope and add some overhead for saving data)

Klaus
 

Hello again,
My problem doesn't happen any more, so the problem cause was the enable_interrupt(GLOBAL) just before exiting the interrupt.
I have another small problem:
Code:
fputc((int16)address|tempID, RS485);
while(!PIR1TXIF);
fputc((int16)address|tempTo, RS485);
while(!PIR1TXIF);
fputc((int16)address|length, RS485);
...
I was previously using 2ms delay instead of while(!PIR1TXIF), after I started waiting TXIF, it seems to stuck sometimes. If I use 2ms delay between every character sending, the problems doesnt seem to happen.
 

Shouldn't the RS485 driver already care for transmitter readiness?
 

I think it doesnt, because communication is stuck if I remove the delays.
 

I guess you need delay between 16 bit entities for framing, if so polling PIR1TXIF won't work neither.
 
  • Like
Reactions: apsua

    apsua

    Points: 2
    Helpful Answer Positive Rating
So I will use a 100us delay between every fputc. I will test.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top