Help to Write a Example Program to blink LED when i push button SW1/SW2 on the M52223EVB

cancel
Showing results for 
Search instead for 
Did you mean: 

Help to Write a Example Program to blink LED when i push button SW1/SW2 on the M52223EVB

6,209 Views
matthew_eli
Contributor I
Hi to all

I'm an Italian Grant Researcher at Università Politecnica delle Marche and i'm trying to use the evaluation board M52223EVB.
I read some pages of the Reference Manual (MCF52223RM) and the board UG (M52223EVB_UG), but this is the first time i'm trying to program a Microcontroller and i've some problem.
Fortunately, i found the software ColdFire Init, but this didn't solve all my problems. I managed to blink some Led and i understand what resgisters are implied.
My objective now is to blink a led when i push one of the two user button (SW1 or SW2), but i didn't understand what registers i would have to use.

Thanks to all in advance.

Dr Rosettani, UNIVPM
Labels (1)
0 Kudos
8 Replies

57 Views
danieljabad
Contributor I
Hi Dr Rosettani,
I' began to work with MFC52210  & MFC52233  few weeks ago.
I 'm from Milano and I would like to exchange ideas and problems with
you.
Daniel Abad 
0 Kudos

57 Views
mjbcswitzerland
Specialist V
Hi
 
Please take a look at the uTasker project - www.uTasker.com.
As well as OS, TCP/IP and device drivers, it also contains demos of using the edge port interrupts (SW1, SW2 etc.) and the LEDs (the LEDs can also be controlled via Web Browser).
 
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. 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

57 Views
Technoman64
Contributor III
Port NQ has configuration registers that pertain to using the port pins with the Interrupt logic and/or general purpose i/o
 
This code configures PORT NQ as bits 1-6 inputs, bit 7 output, and all bits as general purpose i/o with no interrupt logic.
 
Code:
    MCF_GPIO_DDRNQ = MCF_GPIO_DDRNQ_DDRNQ7;    MCF_GPIO_PNQPAR = 0;    /* Pins 1-6 configured as GPIO inputs        Pin NQ7 configured as GPIO output        Pin NQ6 as input       Pin NQ5 as input        Pin NQ4 as input       Pin NQ3 as input       Pin NQ2 as input       Pin NQ1 as input    */    MCF_EPORT_EPPAR = 0;    MCF_EPORT_EPDDR = MCF_EPORT_EPDDR_EPDD7;    MCF_EPORT_EPIER = 0;    MCF_GPIO_PORTNQ = 0;

 
When reading the port value you need to isolate just the port pin/bit you are interested in. The following MACROS will return the port pin state with all other bits masked off.
Code:
/* MACROS to set, clear PORTNQ7 */#define NQ_BIT7_HIGH   MCF_GPIO_SETNQ = MCF_GPIO_SETNQ_SETNQ7 #define NQ_BIT7_LOW   MCF_GPIO_CLRNQ = 0x7F;/* MACROS to read PORTNQ bits 1-6 */#define READ_PORTNQ  MCF_GPIO_SETNQ &= 0x7E#define PORTNQ_BIT1 0x02#define PORTNQ_BIT2 0x04#define PORTNQ_BIT3  0x08#define PORTNQ_BIT4 0x10#define PORTNQ_BIT5 0x20#define PORTNQ_BIT6 0x40

 
Example to read input
 
char Switch1 = 0;
 
/* Read PORTNQ */
Switch1 = READ_PORTNQ;
/* Isolate bit5 */
Switch1 &= PORTNQ_BIT5;
 
Be sure to check wehter the switch is wired for postive or negative logic. Does the switch have a pull-up or pull-down resistor?
 
This code allows me to read inputs and control POTNQ7 as output with MCF52223 mcu.
 
Hope it helps...
 


Message Edited by Technoman64 on 2007-09-05 10:22 PM
0 Kudos

57 Views
matthew_eli
Contributor I
Thank you! your help was very useful to me: i manage to blink leds 1 and 2 when i push SW1 or SW2 Button.

This is the code:
Code:
#include <stdio.h>#include "common.h"int main (){    int      i;    int Switch1 = 0, Switch2 = 0;     MCF_GPIO_PORTTC = 0x0;    while (1) {     Switch1 = READ_PORTNQ;     Switch1 &= MCF_GPIO_PORTNQ_PORTNQ5;     Switch2 = READ_PORTNQ;     Switch2 &= MCF_GPIO_PORTNQ_PORTNQ1;     if (Switch1 == 0x0)      MCF_GPIO_PORTTC = 0x1;     else     {      if (Switch2 == 0x0)       MCF_GPIO_PORTTC = 0x2;      else       MCF_GPIO_PORTTC = 0x0;     }    }}

 with
Code:
static void init_eport (void){    // Pins 1-7 configured as GPIO inputs    MCF_EPORT_EPPAR = 0;    MCF_EPORT_EPDDR = 0;    MCF_EPORT_EPIER = 0;}static void init_pin_assignments (void){    // Pin assignments for port NQ    //     Pins are all used for EdgePort GPIO/IRQ    MCF_GPIO_DDRNQ = 0;    MCF_GPIO_PNQPAR = 0;    MCF_GPIO_PORTNQ = 0;.../* Bit definitions and macros for MCF_GPIO_PORTNQ */#define NQ_BIT7_HIGH   MCF_GPIO_SETNQ = 0x80;#define READ_PORTNQ  MCF_GPIO_SETNQ &= 0x7E;#define MCF_GPIO_PORTNQ_PORTNQ1              (0x2)#define MCF_GPIO_PORTNQ_PORTNQ2              (0x4)#define MCF_GPIO_PORTNQ_PORTNQ3              (0x8)#define MCF_GPIO_PORTNQ_PORTNQ4              (0x10)#define MCF_GPIO_PORTNQ_PORTNQ5              (0x20)#define MCF_GPIO_PORTNQ_PORTNQ6              (0x40)#define MCF_GPIO_PORTNQ_PORTNQ7              (0x80)...

 Now i will read better the RM and particularly the GPIO chapter.

Thanks to all

M. Rosettani - UNIVPM


0 Kudos

57 Views
J2MEJediMaster
Specialist I
First, find the M52223EVB's schematic, which should be a file on the board's distribution CD. Track down SW1 or SW2 on it. (If the schematic file is an Acrobat file, you can even use the Find feature to bring you right to the spot with the switches.) From there, you have to track the switch lines back to a specific port on the M52223 CPU. Now it's a trip to the M52223's User Guide, to find out which peripherals are on that port, and which registers bits in the peripheral handle the lines that SW1 and SW2 are wired to.

---Tom

0 Kudos

57 Views
matthew_eli
Contributor I
Thanks for the help!
I knew that the SW1 is linked to the IRQ5 port of the M52223 CPU and that the register is the 8 bits of PORTNQ. But when i read in the Debug mode the value of a variable:

Code:
d = MCF_GPIO_PORTNQ;

 its value is always 254, also when i'm keeping pushed the SW1 button.
Here is the code i'm using (generated by CFinit) for main.c:
Code:
/* * File:  main.c * Purpose:  sample program * */#include <stdio.h>#include "common.h"int main (){    while (1) {     if (MCF_GPIO_PORTNQ == MCF_GPIO_PORTNQ_PORTNQ5)            MCF_GPIO_PORTTC = 0x1;        else              MCF_GPIO_PORTTC = 0x2;    }}

MCF_GPIO_PORTNQ_PORTNQ5 = 0x20


This is the Configuration File for the CFInit Utility:

http://files-upload.com/files/482298/configuration.CF


I do not understand where is the problem...


0 Kudos

57 Views
J2MEJediMaster
Specialist I
In your source code, you're going to have to: first, program the the port to be GPIO (sometimes these pins can be configured to serve several different functions), and second, program to GPIO lines to SW2 and SW2 to be configured as inputs. That information will be in the User Guide. Sorry I can't help you more than that. I don't have access to a M52223EVB board.

---Tom
0 Kudos

57 Views
matthew_eli
Contributor I


J2MEJediMaster wrote:
first, program the the port to be GPIO



Well, i think that this is the code to join the port (PORTNQ) to GPIO:
Code:
#define MCF_GPIO_PORTNQ                      (*(vuint8 *)(&__IPSBAR[0x100008]))

 

J2MEJediMaster wrote:
... and second, program to GPIO lines to SW2 and SW2 to be configured as inputs...
---Tom


I don't undersand the meaning of "Program to GPIO lines to SW2" but i think that the problem is that the SW1 is joined to IRQ5 interrupt and i don't undestand why the 8 bit register PORTNQ doesn't manage to bring the "1" in the 6th bit when i push the SW1 button:

SW1 --<push>--> IRQ5 ----> PORTNQ[0:7]

The problem is that i though initialize the PORTNQ register at 0x0, when i push the SW1 button this value remains 0x0 and not 0x20 that i expect.

Sorry but, i repeat, i'm making a mistake, but i don't understand what...




0 Kudos