drivers for accelerometer or LCD for M52233DEMO?

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

drivers for accelerometer or LCD for M52233DEMO?

3,380 Views
regehr
Contributor I
I teach an undergraduate embedded software course and this Fall we are using the M52233DEMO boards for the first time.  These are most excellent, we're having a great time with them.  They are a real improvement over the ARM-based boards that I had used for projects in my course for the past several years.

Anyway, I am wondering if anyone would be willing to share their driver for the accelerometer on these boards?  I am also looking for software that permits the 52233 to drive the LCD on a PBMCUSLK project board into which the ColdFire demo board is plugged.

Creating these drivers from scratch is too much to expect of my students, and it will be difficult for me to make time to hack this code up on my own.  So any help is appreciated.

Thanks,

John Regehr

Labels (1)
0 Kudos
Reply
5 Replies

772 Views
mjbcswitzerland
Specialist V
Hi John
 
We don't have the accelerometer in the project but the rest is available - including LCD and an LCD simulator. Please take a look at the uTasker project - www.uTasker.com which includes an OS, TCP/IP and pretty much all device drivers for the M5223X.
 
The project is open source and free for educational use. Projects for CodeWarrior and Eclipse GCC and included. All users receive free email support and the project has ist own users' forum at http://www.uTasker.com/forum/
The project is rounded off with an M5223X simulator which allows the complete projects to be simulated in 'real-time' on a PC without need for hardware (including an LCD). The simulated device maps its UARTs to COM ports and its Ethernet interface to the PC's NIC so it contactable by other PCs and devices in a real network.
Additionally the uTasker is ideal for students (it doesn't necessarily need HW, it works with open source tool chain, the simulator can play back Ethereal recordings to analyse TCP/IP and all code - including interrupt rourtines, it has a users' forum and lots of documentation!).
 
Regards
 
Mark Butcher


0 Kudos
Reply

772 Views
regehr
Contributor I
Thanks Mark, this looks excellent.  I'll give your software a try.

0 Kudos
Reply

772 Views
macl
Senior Contributor I
I know this is a bit late, but were you able to get code for the accelerometer?  The accelerometer on the demo board has analog outputs which are connected to the ADC inputs on the MCU.  Therefore the only driver code you would need would be to setup and read the results from the ADC.  This code should be available in our software example code.
 
Here is a link to MCF5213 code examples.  This device shares the same ADC.
 
0 Kudos
Reply

772 Views
regehr
Contributor I
Hi-

Yes it was not hard writing an accelerometer driver (see below) but I am seeing some odd results.  Probably my driver is doing something stupid but I haven't figured it out yet.

My program configures AN0-AN7 as ADC inputs and then samples all of these values in sequential one-shot mode.  It prints them to the console after averaging over a number of values.

What I see is AN0 correctly reads the pot and AN4 gives a nice strong signal for the X axis of the accelerometer.  However I am seeing no Y or Z signals coming from AN5 and AN6.

Note that there is one little wrinkle: port TA bit 2 needs to be a digital output set high to ensure that the accelerometer does not sleep.  Bits 0 and 1 can be left as inputs -- the accelerometer manual says that if these pins float, it default to the most sensitive setting.

Finally I am wondering just a bit what a 6 G accelerometer is doing on a demo board.  If I have my students turn these boards into Wii controllers they're all going to get broken :smileyhappy:.

John Regehr


Code:
#include "support_common.h" /* include peripheral declarations and more */#include <stdio.h>static void init_porttc (void){ //user LEDs    /* Enable signals as GPIO */    MCF_GPIO_PTCPAR = 0        | MCF_GPIO_PTCPAR_DTIN3_GPIO        | MCF_GPIO_PTCPAR_DTIN2_GPIO        | MCF_GPIO_PTCPAR_DTIN1_GPIO        | MCF_GPIO_PTCPAR_DTIN0_GPIO;       /* Enable signals as digital outputs */    MCF_GPIO_DDRTC = 0        | MCF_GPIO_DDRTC_DDRTC3        | MCF_GPIO_DDRTC_DDRTC2        | MCF_GPIO_DDRTC_DDRTC1        | MCF_GPIO_DDRTC_DDRTC0; MCF_GPIO_PORTTC = 0x00; // TURN LEDS OFF}static void init_portta (void){ MCF_GPIO_PORTTA = 0;    MCF_GPIO_DDRTA = MCF_GPIO_DDRTA_DDRTA2;    MCF_GPIO_PTAPAR = 0;        // set bit 2 high -- no sleep for accelerometer    MCF_GPIO_PORTTA = 0x4;}static void init_port_an (void){   // all 8 are ADC inputs    MCF_GPIO_DDRAN = 0;    MCF_GPIO_PANPAR |= MCF_GPIO_PANPAR_PANPAR0 |            MCF_GPIO_PANPAR_PANPAR1 |            MCF_GPIO_PANPAR_PANPAR2 |           MCF_GPIO_PANPAR_PANPAR3 |           MCF_GPIO_PANPAR_PANPAR4 |           MCF_GPIO_PANPAR_PANPAR5 |            MCF_GPIO_PANPAR_PANPAR6 |            MCF_GPIO_PANPAR_PANPAR7;     }static void init_adc (void){    /* Initialise LOLIM, HILIM and OFFST registers of enabled channels: */    MCF_ADC_ADLLMT0 = 0;    MCF_ADC_ADHLMT0 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS0 = 0;    MCF_ADC_ADLLMT1 = 0;    MCF_ADC_ADHLMT1 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS1 = 0;    MCF_ADC_ADLLMT2 = 0;    MCF_ADC_ADHLMT2 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS2 = 0;    MCF_ADC_ADLLMT3 = 0;    MCF_ADC_ADHLMT3 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS3 = 0;    MCF_ADC_ADLLMT4 = 0;    MCF_ADC_ADHLMT4 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS4 = 0;    MCF_ADC_ADLLMT5 = 0;    MCF_ADC_ADHLMT5 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS5 = 0;    MCF_ADC_ADLLMT6 = 0;    MCF_ADC_ADHLMT6 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS6 = 0;    MCF_ADC_ADLLMT7 = 0;    MCF_ADC_ADHLMT7 = MCF_ADC_ADHLMT_HLMT(0xfff);    MCF_ADC_ADOFS7 = 0;    /* Initialise ADC */    MCF_ADC_ADZCC = 0;    MCF_ADC_ADLST1 = MCF_ADC_ADLST1_SAMPLE0(0) |               MCF_ADC_ADLST1_SAMPLE1(1) |         MCF_ADC_ADLST1_SAMPLE2(2) |               MCF_ADC_ADLST1_SAMPLE3(3);    MCF_ADC_ADLST2 = MCF_ADC_ADLST2_SAMPLE4(4) |               MCF_ADC_ADLST2_SAMPLE5(5) |         MCF_ADC_ADLST2_SAMPLE6(6) |               MCF_ADC_ADLST2_SAMPLE7(7);    MCF_ADC_ADSDIS = 0;    MCF_ADC_CAL = 0;    MCF_ADC_CTRL1 = 0;    MCF_ADC_CTRL2 = MCF_ADC_CTRL2_STOP1 |                    MCF_ADC_CTRL2_DIV(0x2);    /* Power up ADC converter(s) in use */    MCF_ADC_POWER = MCF_ADC_POWER_PUDELAY(0xd) |                    MCF_ADC_POWER_PD2;    /* Wait for converter A power up to complete */    while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)        ;    /* Wait for converter B power up to complete */    while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS1)        ;}int main(void){ int i = 0; init_porttc(); init_portta(); init_port_an(); init_adc(); while (1) { #define N 10    int res[N][8], avg[8];    int j, k;        // for (x=0; x<100000; x++) asm { nop; }    MCF_ADC_CTRL1 = 0;    MCF_ADC_CTRL1 = MCF_ADC_CTRL1_START0; #define ALL_RDY (MCF_ADC_ADSTAT_RDY0 | MCF_ADC_ADSTAT_RDY1 | MCF_ADC_ADSTAT_RDY2 | MCF_ADC_ADSTAT_RDY3 | MCF_ADC_ADSTAT_RDY4 | MCF_ADC_ADSTAT_RDY5 | MCF_ADC_ADSTAT_RDY6 | MCF_ADC_ADSTAT_RDY7)    while ((MCF_ADC_ADSTAT & ALL_RDY) != ALL_RDY)      ;          res[i][0] = MCF_ADC_ADRSLT0 >> 3;    res[i][1] = MCF_ADC_ADRSLT1 >> 3;    res[i][2] = MCF_ADC_ADRSLT2 >> 3;    res[i][3] = MCF_ADC_ADRSLT3 >> 3;    res[i][4] = MCF_ADC_ADRSLT4 >> 3;    res[i][5] = MCF_ADC_ADRSLT5 >> 3;    res[i][6] = MCF_ADC_ADRSLT6 >> 3;    res[i][7] = MCF_ADC_ADRSLT7 >> 3;    i++;    if (i >= N) i=0;       MCF_ADC_CTRL1 |= MCF_ADC_CTRL1_STOP0;       for (k=0; k<8; k++) {         int t = 0;      for (j=0; j<N; j++) t += res[j][k];      avg[k] = t/N;       }       printf ("AN0 %4d   AN1 %4d   AN2 %4d   AN3 %4d   AN4 %4d   AN5 %4d   AN6 %4d   AN7 %4d\n",       avg[0], avg[1], avg[2], avg[3],       avg[4], avg[5], avg[6], avg[7]);    // blink a LED           MCF_GPIO_PORTTC ^= 0x8; }}

 

0 Kudos
Reply

772 Views
regehr
Contributor I
Well, I did not figure out what was wrong with my previous accelerometer driver, but I messed with the ADC settings a bit and the one below works.

John Regehr


Code:
#include "support_common.h"#include <stdio.h>static void init_portta (void){  MCF_GPIO_PORTTA = 0;  MCF_GPIO_DDRTA =     MCF_GPIO_DDRTA_DDRTA0 |     MCF_GPIO_DDRTA_DDRTA1 |     MCF_GPIO_DDRTA_DDRTA2;  MCF_GPIO_PTAPAR = 0;      // set bit 2 high -- no sleep for accelerometer  MCF_GPIO_PORTTA = 0x7;}static void init_port_an (void){   // pot, accel x, y, and z channels are input  MCF_GPIO_DDRAN = 0;  MCF_GPIO_PANPAR |= MCF_GPIO_PANPAR_PANPAR0 |    MCF_GPIO_PANPAR_PANPAR4 |    MCF_GPIO_PANPAR_PANPAR5 |     MCF_GPIO_PANPAR_PANPAR6;}static void init_adc (void){  /* Initialise LOLIM, HILIM and OFFST registers of enabled channels: */  MCF_ADC_ADLLMT0 = 0;  MCF_ADC_ADHLMT0 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS0 = 0;  MCF_ADC_ADLLMT1 = 0;  MCF_ADC_ADHLMT1 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS1 = 0;  MCF_ADC_ADLLMT2 = 0;  MCF_ADC_ADHLMT2 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS2 = 0;  MCF_ADC_ADLLMT3 = 0;  MCF_ADC_ADHLMT3 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS3 = 0;  MCF_ADC_ADLLMT4 = 0;  MCF_ADC_ADHLMT4 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS4 = 0;  MCF_ADC_ADLLMT5 = 0;  MCF_ADC_ADHLMT5 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS5 = 0;  MCF_ADC_ADLLMT6 = 0;  MCF_ADC_ADHLMT6 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS6 = 0;  MCF_ADC_ADLLMT7 = 0;  MCF_ADC_ADHLMT7 = MCF_ADC_ADHLMT_HLMT(0xfff);  MCF_ADC_ADOFS7 = 0;  MCF_ADC_ADZCC = 0;  MCF_ADC_ADLST1 = MCF_ADC_ADLST1_SAMPLE0(4) |    MCF_ADC_ADLST1_SAMPLE1(5) |    MCF_ADC_ADLST1_SAMPLE2(6) |     MCF_ADC_ADLST1_SAMPLE3(0);  MCF_ADC_ADLST2 = 0;  MCF_ADC_ADSDIS = 0;  MCF_ADC_CAL = 0;  MCF_ADC_CTRL1 = 0;  MCF_ADC_CTRL2 = MCF_ADC_CTRL2_STOP1 |    MCF_ADC_CTRL2_DIV(0x2);  /* Power up ADC converter(s) in use */  MCF_ADC_POWER = MCF_ADC_POWER_PUDELAY(0xd) |    MCF_ADC_POWER_PD2;  /* Wait for converter A power up to complete */  while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS0)    ;  /* Wait for converter B power up to complete */  while (MCF_ADC_POWER & MCF_ADC_POWER_PSTS1)    ;}#define ALL_RDY (MCF_ADC_ADSTAT_RDY0 | MCF_ADC_ADSTAT_RDY1 | MCF_ADC_ADSTAT_RDY2 | MCF_ADC_ADSTAT_RDY3)#define N 10int main(void){  int i = 0;  init_portta();  init_port_an();  init_adc();  while (1) {     int res[N][8], avg[8];    int j, k;        MCF_ADC_CTRL1 = 0;    MCF_ADC_CTRL1 = MCF_ADC_CTRL1_START0;     while ((MCF_ADC_ADSTAT & ALL_RDY) != ALL_RDY)      ;          res[i][0] = MCF_ADC_ADRSLT0 >> 3;    res[i][1] = MCF_ADC_ADRSLT1 >> 3;    res[i][2] = MCF_ADC_ADRSLT2 >> 3;    res[i][3] = MCF_ADC_ADRSLT3 >> 3;    i++;    if (i >= N) i=0;    MCF_ADC_CTRL1 |= MCF_ADC_CTRL1_STOP0;    for (k=0; k<8; k++) {      int t = 0;      for (j=0; j<N; j++) t += res[j][k];      avg[k] = t/N;    }    printf ("X= %4d   Y= %4d   Z= %4d   pot= %4d\n",     avg[0], avg[1], avg[2], avg[3]);  }}

 

0 Kudos
Reply