I have trouble with using MKW22D512VHA to communicate with my sensors(freescale MMA8451Q) by i2c.I use freescale beekit to generate a wireless uart project.There are some files about i2c under MKW22D\WirelessUART\PLM\Source\IIC. But I don't know to communicate with i2c device like my sensors.Could someone help?Thanks!
The Ultra low cost ZigBee Evaluation Board package contains sample software interfacing the MKW24D512 and a FXOS8700, which should be very similar to the MMA8451 accelerometer. The software was developed based in SMAC wireless UART. You may use the I2C part of it for your project and change the register values of FXOS8700 to match the MMA8451 ones.
You may also download the FRDM-KL25Z and TWRKL25Z48M Sample Code Package, which contains a baremetal I2C driver and functions to read the MMA8451 (FRDM_KL25ZDemo folder). You may need to update the register definitions to match those of MKW2x.
I checked EVB code in "WirelessUART_MKW2x_v1.3_eCompass_v1", the I2c.c seems too simple compare to the Beekit generated I2C.c API. Also in "WirelessUART_MKW2x_v1.3_eCompass_v1.pdf" mentioned " I2C drivers used are simply for evaluation purposes and should be taken only as example. Support might be limited".
As we need an I2C driver support for both Master and Slave mode. Beekit generated code seems to meet this requirement, with API such as:
bool_t IIC_Transmit_Master(), and others...
I have checked Beekit installed documentations, only to find reference manuals described the interface protocol of I2C driver. Can you tell me where to find an user example, for both Master and Slave mode, how to call these APIs?
Unfortunately there is not any example usage of the driver. Functions have been tested to work individually, but a custom application such as one using MMA8451 may require customized functions too. The BeeStack drivers in general are provided to ease customer’s development phase, but it is also true they will not fit all application’s use cases.
If I2C drivers in BeeStack application do not fulfill your application’s requirements, you could always modify them or create your own drivers for your very specific application. All of the functions are provided in source code in case you would like to re-use them. Sorry for the inconvenience.
I modified BeeStack ZHA GenericApp I2C driver to use a FXOS8700 sensor. This is very similar to MMA8451, so the same code could be used for it. There might be several ways to implement a FXOS8700 driver, ones better than others, but this simple yet useful approach may help you with your implementation.
Please notice the example is provided as is, and the support of it is limited. Significant changes to the original template could be identified with “FXOS8700 demo”. I hope it helps.
We have tried your project code, it works. Thanks!
Next step is to develop for Slave mode. Based on our experience, this is much complicate compared to Master mode. What is your suggestion? Do you have any plan on this?
A typical application using FXOS8700 would imply the MKW2x is the master device. If you would like to interface it with another device acting as a master you could use the available functions. There are no plans to change the available drivers. If they do not fulfill the application’s requirements, then you can modify them as done with the FXOS8700 example. I ignore how many changes are to be done, depends in the specific application and the expected functionality.
hello Benjamin, the driver code has some problems.First you need to check some inital work in the iic_init function.Modify it to adapt to your hardware.for the master mode, you can use the iictransmitmaster function you have mentioned to transmit data.Be ware your iic address.As the ak.signal received,iic_isr function would be responsed.your transmit callback function would be called.But the generated code still has some problems.according to the iic single byte read timing diagram,repeated signal should be sent after writing register address.but there is no repeated signal in this driver,you need to modify it in the iicisr function.with the respect of slave mode,i haven't tried.but i think they are similiar.good luck for you.
来自 lyuchen zhao