Hey all,
I am trying to learn my way through the FRDM-KE02Z board using Kinetis Design Studio.
For this set of experiments, I am trying to communicate (I2C) with the on-board accelerometer (MMA8451Q).
Currently, I am trying to debug through consoleIO using printf, and this bit seems to work fine.
However, it would appear that I am doing something horribly wrong in the way I am trying to communicate with the I2C module...
Since I'm using the processor expert "beans," I guess I need to supply some background, so here goes:
~~~~~~~ CPU settings ~~~~~~~~~~~
CPU type: MKE02Z64VLH2 (yes, I know this is incorrect, but KDS won't let me select the VQH2 option)
Interrupts enabled
watchdog disabled
clock: 10MHz external crystal
Internal peripherals:
NMI disabled
Reset pin enabled
Flash config field disabled
MCM setting not selected
LVD module not selected
Clock Gating not selected
All CPU interrupts/resets disabled
Low power settings not selected
Clock config : ~16.8MHz bus/core clock
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have added also an internal I2C component (named Accelerometer)
This component uses I2C0 in Master mode, with an internal freq of ~4.2MHz
frequency divider bits give an SCL freq of ~95kHz with an SDA hold time of ~2.6us
I have tried using this component both with, and without the Interrupt service event enabled.
The device is set up for 7-bit addressing and high speed mode.
~~~~~~~~~ Code (Major comments removed)~~~~~~~~~~~~~~
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "CsIO.h"
#include "IO1.h"
#include "Accelerometer.h"
#include "IntI2cLdd1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <stdio.h>
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
char AData[7] = {0,1,2,3,4,5,6}; // Funny initialization for troubleshooting
unsigned short status = 0x55;
short xG = 0;
short yG = 0;
short zG = 0;
word bytes = 0;
int error = 58;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
error = Accelerometer_Enable(); // enable the accelerometer
printf("Err:%3d \r\n", error);
error = Accelerometer_SelectSlave(0x1D); // accelerometer address is 0x1D
printf("Err:%3d \r\n", error);
error = Accelerometer_SendChar(0x40); // reset the accelerometer
printf("Err:%3d \r\n", error);
error = Accelerometer_SendChar(0x00); // Send start address
printf("Err:%3d \r\n", error);
error = Accelerometer_RecvBlock(AData, 7, &bytes); // read back 7 bytes
printf("Err:%3d \r\n", error);
error = Accelerometer_RecvChar(&bytes);
printf("Err:%3d \r\n", error);
status = AData[0];
// xG = (AData[1]<<8) + AData[2];
// yG = (AData[3]<<8) + AData[4];
// zG = (AData[5]<<8) + AData[6];
xG = AData[1];
yG = AData[3];
zG = AData[5];
printf("Err:%3d BytesRX:%3d Status:%3d X:%6d Y:%6d Z:%6d\r\n", error, bytes, status, xG, yG, zG);
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
~~~~~~~~~~~~~~~~~~~ END CODE ~~~~~~~~~~~~~~~~~~~~~~
Running this results in the following output:
Err: 0
Err: 7
Err: 7
Err: 7
Err: 7
Err: 7
Err: 7 BytesRX: 0 Status: 0 X: 1 Y: 3 Z: 5
Error 7 seems to be "ERR_DISABLED" ???
Yesterday evening, I also saw a an error 12 "ERR_BUSOFF" ??
Any clues? Help, please? Probably something simple I'm missing, but I'd sure like to get it sorted out.
Thanks in advance,
-Tom