AnsweredAssumed Answered

KL46Z I2C problems

Question asked by Wenbo Qi on Mar 22, 2017
Latest reply on Mar 30, 2017 by Wenbo Qi

Hello,

 

I am currently working on writing a very basic I2C communication library for KL46Z who is capable of sending start, stop signals and sending to or receiving from a slave device . My environment is similar to KSDK. I am trying to use the I2C1 on port E pin 1 and pin 0 on the development board. But after initializing the corresponding port and pins, and ungating the clock, I could not write to the I2C1 registers. For example, to activate the I2C module on I2C1, the bit 7 of register I2C1_C1 must be set to 1. So my code is simply:

 

void I2C_activate(I2C_Type *base){
base->C1 |= 1U<<7;

 

Using it afterwards is something like:

 

I2C_activate(I2C1);

 

Normally, this function would simply set the 7th bit of I2C1_C1 register. But instead, I get a hard fault...

Can somebody please tell me if I am doing right? Did I forget something before writing in the register? 

 

Thank you in advance!

 

Outcomes