Cannot write in I2C register FRDM-MKL43Z

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Cannot write in I2C register FRDM-MKL43Z

1,033 次查看
grec_mihai96
Contributor I

   Hello, I am trying to make a small driver for the I2C communication for better undersanding how everything works here and to get used to working with the registers. All I am trying to do by now is to enable the ports for the I2C comm, enable the clock and enable I2C module operation and I2C Interrupt enable in I2C Control Register 1. My code is:

   I2C_Type* i2c[] = I2C_BASE_PTRS;//defined in MKL43Z4.h as 2 pointers who point at the corresponding addresses

  CLOCK_EnableClock(kCLOCK_PortE);//using PORTE PINS 24, 25 for I2C0

  PORT_SetPinMux(PORTE, 24U, kPORT_MuxAlt5);
  PORT_SetPinMux(PORTE, 25U, kPORT_MuxAlt5);
  SIM->SCGC4 |= 1u << 6u;//enable the clock gate to the I2C0 module

   i2c[0]->C1 = 1u << 7u | 1u << 6u;//I2C0 Control Register

   When I debug this code, it goes past the writing in SIM->SCGC4 register, but when I arrive at the last line, it takes me at "startup_MKL43Z4.S" file at line 209, where is the following code:

HardFault_Handler:

ldr r0,=HardFault_Handler
bx r0
.size HardFault_Handler, . - HardFault_Handler

.align 1
.thumb_func
.weak SVC_Handler
.type SVC_Handler, %function

Codewise I don't think that I do something wrong, I believe that probably it's some settings or initializations that I didn't take in considerations. Thanks in advance and have a nice day everyone!

标签 (1)
标记 (2)
0 项奖励
回复
1 回复

929 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

Please try the code show below:

I2C0->C1 |= I2C_C1_IICEN_MASK|I2C_C1_IICIE_MASK;

Best Regards,

Robin

 

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

0 项奖励
回复