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:
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
解決済! 解決策の投稿を見る。
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!
-----------------------------------------------------------------------------------------------------------------------
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!
-----------------------------------------------------------------------------------------------------------------------
Thanks!
I found this code in an I2C kl43z example:
Would using (const uint8_t) rather than passing the address as a pointer achieve the same result?
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
Okay thanks
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