I2C Master Driver Hanging on Kinetis K22.

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Master Driver Hanging on Kinetis K22.

Jump to solution
1,199 Views
bosleymusic_com
Contributor IV

Trying to use the I2C Master Driver in a Bare Metal application.

Currently when I use the I2C Master Driver I'm ending up here :

 

Default_Handler:

  b .

  .size Default_Handler, . - Default_Handler

 

Tracing the error backwards, this is the function sequence :

 

I2C_DRV_MasterSendDataBlocking calls I2C_DRV_SendAddress calls I2C_DRV_MasterWait calls OSA_SemaWait calls OSA_TimeGetMsec() calls LPTMR_HAL_GetCounterValue(uint32_t baseAddr):

 

static inline uint32_t LPTMR_HAL_GetCounterValue(uint32_t baseAddr)

{

    BW_LPTMR_CNR_COUNTER(baseAddr, 0);  /* Must first write to the CNR with any value */

    return (uint32_t)(BR_LPTMR_CNR_COUNTER(baseAddr) & 0xFFFFU);

}

 

Where:

/*! @brief Set the COUNTER field to a new value. */

#define BW_LPTMR_CNR_COUNTER(x, v) (HW_LPTMR_CNR_WR(x, (HW_LPTMR_CNR_RD(x) & ~BM_LPTMR_CNR_COUNTER) | BF_LPTMR_CNR_COUNTER(v)))

/*@}*/


The baseAddr is 04004000 which is correct for LPTMR, and I have verified the LPTMR is enabled (set up by OSA_Init, called in my main).

 

Anyone had this problem and been able to solve it? I will add some of my attempts to solve this as I work through it, but if anyone can point to a solution that would be cool also.

----

EDIT: From a hardware perspective, and I probably should have said this to begin with, the clocking and data are coming out of the pins correctly for the Address send, but then they hang low permanently.

I've tried just hooking to the scope and would think that after the I2C doesn't receive anything back it would reset high - at least that's the way it has worked on other chips I've used...

-----

EDIT II: Ran the i2c_rtos_ucosiii project successfully.

Labels (1)
1 Solution
181 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Donald:

That seems like you are missing the I2C ISR functions. The actual interrupt service code is in fsl_i2c_master_driver.c, but you need a file with the ISRs, which will only call the actual function in the driver.

Attached is the example file I took from the I2C_comm demo of KSDK.

I hope this solves the problem.


Regards!,
Jorge Gonzalez

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

View solution in original post

0 Kudos
5 Replies
181 Views
bosleymusic_com
Contributor IV

Narrowing down the issue a little bit : OSA_status returns success, LPTMR is in motion.

Reviewed registers in I2C as I stepped through :

Control Register IICIE is enabled at I2C_HAL_SendStart(baseAddr) called from I2C_DRV_MasterSendDataBlocking,  but there is no handler defined for the interrupt within the driver or inits...hence dumping into default handler. So, I set I2C_HAL_SetIntCmd within I2C_DRV_MasterSendDataBlocking to false, and voila. EDIT: Crashing worse. Will set up interrupt.

Shouldn't there be something about setting an interrupt in the documentation for the API if it's necessary to operate with the default behavior?

0 Kudos
182 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Donald:

That seems like you are missing the I2C ISR functions. The actual interrupt service code is in fsl_i2c_master_driver.c, but you need a file with the ISRs, which will only call the actual function in the driver.

Attached is the example file I took from the I2C_comm demo of KSDK.

I hope this solves the problem.


Regards!,
Jorge Gonzalez

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

View solution in original post

0 Kudos
181 Views
bosleymusic_com
Contributor IV

Maybe this is a better question to ask since these functions are included in the KSDK files in my includes already. I seem to have issues with include files not showing up when I compile, and I assume this has something to do with my linker or include settings, because with some things, simply declaring #include "X" or "include <X> leads to errors. Is there a common method to fix this, or have these files more easily recognized? I attribute this to lack of understanding with Eclipse, but I am hoping you can point me to a resource or tutorial that help me develop my understanding of how the backend of this IDE works.

Thanks.

0 Kudos
181 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hi Donald:

If trying to include any header file, make sure the corresponding path is added to Project -> Properties -> C/C++ Build -> Settings -> Cross ARM C Compiler -> Includes:

Include_KDS.png

If you are not familiar with Eclipse then it is highly recommended that you visit MCU on Eclipse | Everything on Eclipse, Microcontrollers and Software. This site is maintained by colleague Erich Styger and has lots of tutorials about Eclipse and Embedded Systems in general.

Regards!

Jorge Gonzalez

181 Views
bosleymusic_com
Contributor IV

Thank you, I saw this after I posted my own reply. Not sure if it's a good idea or not, but for a temporary fix, I set a value to false as outlined below :

0 Kudos