Functions for I2C with KL43 SDK and PE?

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

Functions for I2C with KL43 SDK and PE?

Jump to solution
1,263 Views
christopherira
Contributor III


Hello,

 

I am trying to use processor expert with the KL43z SDK I2C component, and I don't know quite where to begin. I am trying to simply write data to my LCD display. Using processor expert I simply initialized the I2C and set the Baud rate to 100 kbit/s, address: 0, unchecked read only. I only have master configurations, not sure if I need slave configurations also.

 

I've tried using the function I2C_DRV_MasterSendData, but I'm not sure what all the parameters should be.

 

The LCD datasheet says in order to clear the screen:

143824_143824.pngpastedImage_0.png

So, I'm guessing this means I send 0x06 across the I2C, so I tried using the following code:

 

I2C_DRV_MasterSendData (i2cCom1_IDX,&i2cCom1_MasterConfig0, NULL, 0, 0x06, 5);

 

Some guidance would be much appreciated.

 

Thanks!

 

-Chris

Labels (1)
0 Kudos
1 Solution
909 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Christopher:

As mentioned by Santiago there are several examples in KSDK installation, you should take a look at those.

Just notice that the MasterSendData API expects the parameter txBuff to be passed by reference, not by value, so in your case you should declare a uint8_t variable or an array of uint8_t and pass the address as a pointer. The parameter txSize is the number of bytes to transfer from such array, or 1 in the uint8_t variable case. Below an example for writing 0x06 to an I2C slave:

uint8_t data = 0x06;

I2C_DRV_MasterSendData (i2cCom1_IDX,&i2cCom1_MasterConfig0, NULL, 0, &data, 1);

About cmdBuff parameter, this is used for some slave devices that require extra bytes apart from the significant data bytes to send or receive. For example the I2C EEPROM memories may require an internal address before a Write or Read operation (do not confuse with the I2C slave address). In the case of the API MasterReceiveData when cmdBuff is not NULL then a Repeated Start is generated between the transmission of cmdBuff and the reception of data in rxBuff, with a corresponding change in the R/W bit.

I hope this helps.


Best regards,
Jorge Gonzalez

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

View solution in original post

5 Replies
910 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Christopher:

As mentioned by Santiago there are several examples in KSDK installation, you should take a look at those.

Just notice that the MasterSendData API expects the parameter txBuff to be passed by reference, not by value, so in your case you should declare a uint8_t variable or an array of uint8_t and pass the address as a pointer. The parameter txSize is the number of bytes to transfer from such array, or 1 in the uint8_t variable case. Below an example for writing 0x06 to an I2C slave:

uint8_t data = 0x06;

I2C_DRV_MasterSendData (i2cCom1_IDX,&i2cCom1_MasterConfig0, NULL, 0, &data, 1);

About cmdBuff parameter, this is used for some slave devices that require extra bytes apart from the significant data bytes to send or receive. For example the I2C EEPROM memories may require an internal address before a Write or Read operation (do not confuse with the I2C slave address). In the case of the API MasterReceiveData when cmdBuff is not NULL then a Repeated Start is generated between the transmission of cmdBuff and the reception of data in rxBuff, with a corresponding change in the R/W bit.

I hope this helps.


Best regards,
Jorge Gonzalez

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

909 Views
christopherira
Contributor III

Thanks!

I found this code in an I2C kl43z example:

pastedImage_0.png

Would using (const uint8_t) rather than passing the address as a pointer achieve the same result?

0 Kudos
909 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Christopher:

No, that would not work. The pointer goes to a run-time state structure which is manipulated by the driver functions and the interrupt handler. All of the driver's code expects to have a pointer in such structure.

Regards!

Jorge Gonzalez

909 Views
christopherira
Contributor III

Okay thanks

0 Kudos
909 Views
santiago_gonzal
NXP Employee
NXP Employee

Hello,

You have a lot of working examples with I2C, here in the community and also in the KSDK 1.3:

C:\Freescale\KSDK_1.3.0\examples\frdmkl43z\driver_examples\i2c

Regards,

Santiago