I need some help!
I'm working on a kl25z for the freescale cup and i'm trying to program the build-in accelerometer...
I just got into college, so I don't know anything about programming processors and stuff like that...
I've tried lots of tutorials, but my CW project does't have the processor expert, and, if I add it, it messes the whole thing...
My software is based on the sample for the TFC...
could someone help me with the code for it?
Hi there fellow college student!
You'll start recognizing people around these boards (the community) and you'll probably start to notice some of the same people posting tutorials or articles they have written on various useful topics. One person has helped me learn a lot, Erich Styger, his blog helps with common issues or questions people may have while their projects excel (MCU on Eclipse | Everything on Eclipse, Microcontrollers and Software) and he has a github account that holds many different demo projects. There are many projects on his github for KL25z and there is a demo project on there for KL25z's accelerometer using processor expert. Here is his github link: ErichStyger/mcuoneclipse · GitHub. Just load the .zip onto your computer and import the Freedom_Accel project on to Eclispe!
Hope this helps,
Yeah... I've searched a lot... but the problem is that int all of the tutorials that I found they all use the process expert... and my code doesn't support it...
If I try to add the process expert it bugs all my code...
I don't really understand. You don't need processor expert because your code doesn't support it, but you try to add it? The rules for the freescale cup say that you can or cannot use processor expert? And when you say bugs, you get errors? What kind of errors?
I can't use processor expert because it conflicts with the parameters in my code!
when I add it I get like 20 errors... then i correct them and i get many others.........
What I think I need is a library for the accelerometer...
like a .c and a .h code for it...
I am giving a software lab course at the University. As students are learning the basics of low-level programming (register level), I do not use Processor Expert in this course. The final experiment is accessing the accelerometer through I2C, so I have developed a library for this purpose, derived from an example library for Kinetis Family, which I simplified and suited for my needs. I am sending the .h and .c files attached to this reply.
For controlling the accelerometer, you just have to write the right values to the right config registers. Remember that the accelerometer address (SlaveID) is 0x1D.
If you just want to read raw (unfiltered) data from XYZ axes, using a full scale range of 2g, you may initialize the accelerometer using this code:
I2CWriteRegister(0x1D, 0x0E, 0x00); // Writes 0x00 to data config register (0x0E).
I2CWriteRegister(0x1D, 0x2A, 0x39); // Writes 0x39 to general config register 1 (0x2A)
Now the accelerometer starts working. It will make a new read (all 3 axes) every 640ms. If you want other periods, you just have to write the right value on 0x2A register, instead of 0x39. For 160ms, write 0x31; for 80ms, write 0x29; for 20ms, write 0x21.
You may read the latest collected values this way:
I2CReadMultiRegisters(0x1D, 0x01, 6, data); // Reads 6 sequential registers starting from MSB of X axis (0x01). "data" is a 6-element array of char.
The result will be the values of 3 axes loaded on "data" array: [MSB_X, LSB_X, MSB_Y, LSB_Y, MSB_Z, LSB_Z]. You may also test if new data is available before reading using:
dr = (I2CReadRegister(0x1D, STATUS) & 0x08); // dr is zero if no new data is available; it is 0x08 if new data is available.
I hope that it helps. Just message me if you need something else.
By the way, Processor Expert should not keep giving you errors. It would be interesting if you could provide more details (including screen captures) about the errors.
I have tried use your code but the code gets stuck in this line:
__asm("bkpt"); // <-------------
after have ran from
I2CWriteRegister(0x1D, 0x0E, 0x00);
Do you have any idea about what can be happening?
When code stucks at the default interrupt handler, it is probably some math error (like divide by zero) or a hardware fault. There is a way to know what kind of error is happening in this case. Just check this link:
Doing this you can see if you have a dardware fault, which is the most probable. Then, check on these 2 links:
You may get more details on your error. Also, create a breakpoint inside i2c_Start() function, right at the beginning and use step-by-step execution, and see in what instruction the interrupt is triggered at.
Post your results so I can help you more.
Hi Antonio, I am getting the exact same issue as Joao, my code getting an interrupt handler error inside 12c_start();. I tried going to the links you provided, but I can't really relate since I'm not using processor expert. Did you come up with any fix for this?
Processor Expert just creates a .c and a .h file for every peripheral of the microcontroller.
In the case of the accelerometer, you will communicate with it through I2C. You can check the example that has been suggested to you from Erich's blog, look at the code that processor expert generates and then try to implement it in your project.
El 17/10/2013, a las 18:17, "Mauricio Farina" <firstname.lastname@example.org<mailto:email@example.com>> escribió:
reply from Mauricio Farina<https://community.freescale.com/people/mauriciofarina?et=watches.email.thread> in Kinetis Microcontrollers - View the full discussion<https://community.freescale.com/message/356413?et=watches.email.thread#356413>