AnsweredAssumed Answered

Cannot write in I2C register FRDM-MKL43Z

Question asked by Mihai Grec on Jul 17, 2018
Latest reply on Jul 18, 2018 by Robin_Shen

   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:


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

.align 1
.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!