step into eeprom_write() but jump to other line

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

step into eeprom_write() but jump to other line

Postby khmok » Fri Mar 22, 2013 12:00 am

Hi,

I am currently using PIC16F873A, MPLAB 8.46, UIC00B programmer/debugger and HI TECH compiler.
Below are few lines at the very beginning of main() where I trying to read and write data eeprom of PIC. I am using debug mode to step in each line and "watch" EEADD and EEDATA. However, something wrong when step into eeprom_write(): it stepping target few times and the arrow stop at some other line - in this case I2C_stop() (refer attachments EEPROM_WRITE_1 & EEPROM_WRITE_2).

can anyone help to explain this?

void main(void)
{
unsigned char rec_data[2];
unsigned char ee_mux_no = 0;
unsigned char address = 0;
unsigned char address2 = 1;
unsigned char value = 171;

ee_mux_no = eeprom_read(address);
eeprom_write(address,value);
ee_mux_no = eeprom_read(address2);
Attachments
EEPROM_WRITE_1.PNG
Step into eeprom_write()
EEPROM_WRITE_2.PNG
Arrow jump to I2C_stop()
khmok
Newbie
 
Posts: 13
Joined: Fri Mar 08, 2013 6:08 pm

Re: step into eeprom_write() but jump to other line

Postby robosang » Fri Mar 22, 2013 9:13 am

As far as I know, when you read or write data from/to EEPROM, the timing is critical and it cannot be interrupt by other source. That is is why in datasheet, it is stated, when dealing with EEPROM, global interrupt is being disabled to prevent any possible interrupt source to disturb the process.

I guess when you are using debugger, it hold the process and the timing is incorrect and the process jump, that is just my point of view.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: step into eeprom_write() but jump to other line

Postby khmok » Fri Mar 22, 2013 9:33 am

I have tried to create a new project, where it only consists of eeprom_read and eeprom_write. Then I step into each function, there is no such problem.

So based on your opinion and my observation above, looked like the program has been interruptted during eeprom_write. But there are few things couldn't explaint this:
1. I don't use any interrupt in my code (hence no ISR).
2. Although I never disabled the IF (interrupt flag), but by default it is disable.
3. It only happen when eeprom_write() but not in eeprom_read().
4. The subroutine that the arrow point to is not ISR and neither the PEN is execute based on interrupt.

Please share more thoughts with me so that I can solve this problem. Thanks a lot.
khmok
Newbie
 
Posts: 13
Joined: Fri Mar 08, 2013 6:08 pm

Re: step into eeprom_write() but jump to other line

Postby robosang » Fri Mar 22, 2013 10:05 am

Yes, I understand there is not ISR or interrupt.

I highlight the interrupt because it is stated in the datasheet that even interrupt cannot happen during the EEPROM process, the main point is the timing to write cannot be disturb.

As I said at the end of my explanation, using debugger change the timing because you need to animate and hold the process to make it slower.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: step into eeprom_write() but jump to other line

Postby khmok » Fri Mar 22, 2013 10:14 am

Do you have any idea how to check the data EEPROM content without entering debug mode?
I want to make sure that the data written into EEPROM of PIC is successfully stored.

Thanks.
khmok
Newbie
 
Posts: 13
Joined: Fri Mar 08, 2013 6:08 pm

Re: step into eeprom_write() but jump to other line

Postby shahrul » Fri Mar 22, 2013 1:04 pm

Test it on real hardware.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: step into eeprom_write() but jump to other line

Postby robosang » Fri Mar 22, 2013 10:48 pm

Yup, with real hardware.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 23 guests