Functions Caused Hard Fault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Functions Caused Hard Fault

1,956 Views
Designer11
Contributor IV

Hi Everyone,

I have a program that contains two functions.  Whenever I run both functions, the program would crash and enter the PE_ISR(Unhandled_ivINT_Hard_Fault) error. Function A reads temperature from a temperature sensor via the I2C bus every 3 seconds. Function B returns a sensor status via the UART whenever the user requests the function to send the status.

The main issue is when both functions are allowed to run, if the user calls function B 5-6 times the program crashes and enters the PE_ISR(Unhandled_ivINT_Hard_Fault). Once the program crashed and restarted. Any subsequent call to function B will make the program to crash.

However, if each function runs independently (commented one function, and allowed the other function to run) I won’t get any ivINT_Hard_Fault error at all.

I’m using Kinetis K64 microcontroller, and I’ve tried to increase the stack size but that didn’t prevent the program from crashing.

Based on the below report I think the crash is within the I2C, but don’t know what causes to crash.

Report:

Designer11_1-1599980347495.png

Disassembly view @ address 0x25CA:

Designer11_2-1599980347672.png

I’ve been working on this issue for about 3 days without any luck. Does anyone have any suggestions that I can try/test?

Sincerely,

Vu

Labels (1)
0 Kudos
9 Replies

1,950 Views
nxf56274
NXP Employee
NXP Employee

Hi,

When you use function B, try to disable the interrupt. When function B goes out, enable interrupt. Like this.

1.PNG

 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,938 Views
Designer11
Contributor IV

Hi TIC,

Thank you very much for your reply. As a new user to the K64 family of microcontrollers why disabling the interrupt help in this situation ? In addition, I have couple questions that I need your help to clarify

- Do you mean If I use  function B disable function A interrupt ? 
- If I disable function B UART interrupt during use, how can I get it to receive and transmit data when a user asks for it ?

 

Thanks,

vu

0 Kudos

1,933 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Function B is used to get the sensor status. So you have to send data by i2c. Function A is used to get temperature by i2c. When you go into B,  if the function A also want to get the i2c, this may has some problems. You can add disable code just for i2c send data in B, not the whole function. Also you can try to add this code for function A. 

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,928 Views
Designer11
Contributor IV

Hi TIC,

I apologize for not being clear. Function B receives the humidity sensor status via the UART not I2C whenever the user request the for the information.

Thanks,

Vu

0 Kudos

1,923 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Try to add code for reading data in function A.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,906 Views
Designer11
Contributor IV

Hi TIC,

I don't think that would work in my current design because:

- Function B handles the interface between the microcontroller and humidity sensor via the UART. Only calls by the user whenever he/she wants to know the status of the sensor.

- Function A handles the temperature between the microcontroller and temperature sensor via I2C, and it automatically runs every 3 seconds without user intervention. 

Thanks,

Vu

0 Kudos

1,900 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Adjust a larger timer for A. Does the question still happen frequently compared with you previous setting?

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,863 Views
Designer11
Contributor IV

Hi TIC,

How would a larger timer helps in this situation ? I'm confused at your question.

 

Thanks,

Vu

0 Kudos

1,859 Views
nxf56274
NXP Employee
NXP Employee

Hi,

A and B works well separately. So we should find why they influence each other. I do not know project in detail. I have to guess the reason. So I guess the timer may influence. If you do not test, I won't give you better ideals.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos