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.

[PIC] can we call EEPROM write function in ISR routine

Status
Not open for further replies.

akshaybhavsar

Full Member level 2
Joined
May 5, 2016
Messages
135
Helped
2
Reputation
4
Reaction score
2
Trophy points
18
Activity points
898
hello guys,
I am working on SIM 900 module.Whenever SMS comes,I want to save it in EEPROM.but problem is EEPROM takes time while reading and writing.so,Can we call that EEPROM_WRITE function in ISR

- - - Updated - - -

plz help me....
 

Hi,

for sure you can.

But it may create (timing) problems in your application. We can not verify this.

I don´t recommend EEPROM writes in an interrupt.

****
If you take care and are sure not to build recursive interrupts you may enable interrupts during EEPROM write. Dangerous!

Klaus
 

You can with most microprocessors, but you shouldn't do.

The fact that you are processing SMS in the interrupt routine is already a case of bad application layout.

You'll receive serial data to a RX ring buffer in the interrupt, but process the modem notifications in the main loop.
 

Hi akshaybhavsar,

It is not recommended to use any extra code (or) implementation in the interrupt handler. It cause desired application to struck & won't work in the expected way.

For your mentioned application, first verify the maximum number of the characters we can text, for example if it is 100 characters, create a buffer with size 200 or more, better double the maximum text size we can.

When ever you receive the data, Rx interrupt is invoked then copy the data in to the receive buffer. what ever the data in the receive buffer copy that data in to the EEPROM process buffer.

When ever the EEPROM process buffer is going to full(i.e set copy data when data more than 150 bytes in 200 bytes buffer), in the main loop pass that buffer in to EEPROM write data function with the initial address & reset that buffer to initial location.

with this implementation you can receive the SMS data & can save in to EEPROM as well.

Let me know if you want to know more info..
 

Actually you can.
:)
set up any flag in an interrupt and when you are out from ISR then serve the ISR request.
 

@Arya Kumar: That is the preferred way of handling cases such as these (or perhaps using a state machine instead of a flag, but the end result it the same). However that is NOT the same as the OP's question which as to call a function (and by implication do the processing ) within the ISR itself.
Also it is a bit misleading to refer to this as "...serv[ing] the ISR request".
Susan
 

No,I cant EEPROM write function in main loop...bcz my code doesnt have while (1) loop..
In my application i am rotating motor for fixed time lets say 10 min..after that application stops.
All those thing probably needs to be done in ISR itself.

- - - Updated - - -

Dera arya kumar

- - - Updated - - -

dear arya kumar
 

Hi akshaybhavsar,

With out using loop, how you are running application?

In my application i am rotating motor for fixed time lets say 10 min..after that application stops.

From your statement when ever you start rotating motor, it will invoke the interrupt. is it correct??
But after code terminated in the main loop, how controller is idling for interrupt?? There should be controller in idle state for interrupt, is it correct??

All those thing probably needs to be done in ISR itself

You can do all the process in interrupt, but it is burden for your application.
 

actually I am setting speed and time for motor by using keypad.
once enter is pressed application starts,motor runs according time and speed.and after that time..application stops.

- - - Updated - - -

Before pressing enter button,system is idle..By that time only it will respond to interrupt??
 

Hi,

I can´t see how it can work without a loop.

usually you "go to idle mode"...then the microcontroller sleeps .. but after every interrrupt it will continoue to process the code after the "goto idle".
I assume the "goto idle" is somewhere within a loop.

Posting your code may clarify things...

Klaus
 

Hi,

cant post code..too much large

source code, attached as compressed ZIP file isn´t large.

Klaus
 

Hi akshaybhavsar,

It is impossible to run the application with out idling the controller.
Better post the source code...
 

I am going to use switch..i will put switch high at the starting of application.It means application is idle until and unless i press the switch.once switch is pressed application starts....

- - - Updated - - -

while in ideal i m going receive sms and save it
 

Hi,

If there is an ISR that can be executed, then there must be a loop in "main" also...

When you say "idle".. what does it mean?
* Processor completely stopped? How? At least after an interupt the processor continues to work...
* or the processor is running in an "idle loop" consuming all of the processing power?

In both cases it is possible to run the EEPROM_write in main.

Klaus
 

If there is an ISR that can be executed, then there must be a loop in "main" also...
I guess the practical problem is that there is more than one "loop", the main loop execution is branching to different code parts and waiting here and there for events or delays to expire.

A reasonable solution if you don't want to change the given application structure is to have work() function performing all periodic housekeeping actions. It can be called during all wait loops. Time delays should be cut into multiple pieces, calling work() in between.

More straightforward you'll rewrite the main code so that it doesn't hang around here and there, instead repeats the main loop the latest after a few 10 milliseconds. This means to replace longer delay statement by software timers and use state machines instead of waiting for events in different places.
 

Sorry i know you are Indian and so we put up all effort without guidance. Actually there is always a better way of doing things.
If ur main() does not have while loop ur program will get exited in few micro second. no matter how long ur code is. No one has ever wrote a embedded program without while(1) loop
In embedded there is always a while(1) loop.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top