Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 18th January 2009, 03:25 AM   #31
Default

I have parallel! Yay

ima try to get the money i need tomorrow. Where should i buy it from? Sparkfun is out of stock on USB TINY thing on the parallel and if im buying parallel i might as well make it lol and buy it also

If i buy parallel and board then its about $98 + $7 shipping/handling so that $105 ... I have $90 on me now. I need $15 tomorrow. That shouldnt be a issue at all! Yeah!

Last edited by AtomSoft; 18th January 2009 at 03:29 AM.
AtomSoft is offline  
Old 18th January 2009, 06:38 AM   #32
Default

Has anyone tried this board from Futurelec?

Mike.
Pommie is online now  
Old 18th January 2009, 10:31 AM   #33
Default

Quote:
Originally Posted by Pommie View Post
Has anyone tried this board from Futurelec?
Hey, that's nice, and decent price! If I didn't already have a 2148 board I'd grab one.

Think I'll dig around in their site and see what else they have... for an upgrade! Ya, that's it! I need an upgrade! Stupid gear lust. Must... Not... Spend... Learn what you already have.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 18th January 2009, 01:54 PM   #34
Default

nice find Pommie(Mike)! The only reason i would still get the other is the RED board lol and also the SD part & 2 serial and looks like the other is mainly LEDs and variable resistors which i have here anyway Cool tho.


I like this board alot!:
SparkFun Electronics - Development Platform for LPC2378

This looks like it would be a nice upgrade:
SparkFun Electronics - Prototyping Board for LPC2294 (1MB)

Last edited by AtomSoft; 18th January 2009 at 02:33 PM.
AtomSoft is offline  
Old 18th January 2009, 05:49 PM   #35
Default

Futz i have a feeling that your issue is Compiler specific. I was reading some info on the RealView MDK :

Quote:
The RealView C compiler provides function attributes that give you access to ARM hardware features. For example:

* __irq allows you to create interrupt service routines in C.
* __swi(id) allows you to invoke a software interrupt handler
from: RealView® Compilation Tools
AtomSoft is offline  
Old 18th January 2009, 07:13 PM   #36
Default

try this as your startup code:
Code:
/* ***************************************************************************************************************
   crt.s                  STARTUP  ASSEMBLY  CODE
                        -----------------------

   Module includes the interrupt vectors and start-up code.
  *************************************************************************************************************** */

/* Stack Sizes */
.set  UND_STACK_SIZE, 0x00000004      /* stack for "undefined instruction" interrupts is 4 bytes  */
.set  ABT_STACK_SIZE, 0x00000004      /* stack for "abort" interrupts is 4 bytes                  */
.set  FIQ_STACK_SIZE, 0x00000004      /* stack for "FIQ" interrupts  is 4 bytes                  */
.set  IRQ_STACK_SIZE, 0X00000004      /* stack for "IRQ" normal interrupts is 4 bytes             */
.set  SVC_STACK_SIZE, 0x00000004      /* stack for "SVC" supervisor mode is 4 bytes              */

#.set _MEMMAP,      0xE01FC040

/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs (program status registers) */
.set  MODE_USR, 0x10                  /* Normal User Mode                               */
.set  MODE_FIQ, 0x11                  /* FIQ Processing Fast Interrupts Mode                   */
.set  MODE_IRQ, 0x12                  /* IRQ Processing Standard Interrupts Mode                */
.set  MODE_SVC, 0x13                  /* Supervisor Processing Software Interrupts Mode          */
.set  MODE_ABT, 0x17                  /* Abort Processing memory Faults Mode                   */
.set  MODE_UND, 0x1B                  /* Undefined Processing Undefined Instructions Mode       */
.set  MODE_SYS, 0x1F                  /* System Running Priviledged Operating System Tasks  Mode   */

.set  I_BIT, 0x80                     /* when I bit is set, IRQ is disabled (program status registers) */
.set  F_BIT, 0x40                     /* when F bit is set, FIQ is disabled (program status registers) */


.text
.arm

.global   Reset_Handler
.global _startup
.func   _startup

_startup:

# Exception Vectors
_vectors:       ldr     PC, Reset_Addr         
                ldr     PC, Undef_Addr
                ldr     PC, SWI_Addr
                ldr     PC, PAbt_Addr
                ldr     PC, DAbt_Addr
                NOP                            ; Reserved Vector
                LDR     PC, IRQ_Addr           ; I added this
                LDR     PC, [PC, #-0x0FF0]     ; Vector from VicVectAddr
                LDR     PC, FIQ_Addr

Reset_Addr:     .word   Reset_Handler      /* defined in this module below  */
Undef_Addr:     .word   UNDEF_Routine      /* defined in main.c  */
SWI_Addr:       .word   SWI_Routine         /* defined in main.c  */
PAbt_Addr:      .word   UNDEF_Routine      /* defined in main.c  */
DAbt_Addr:      .word   UNDEF_Routine      /* defined in main.c  */
IRQ_Addr:       .word   IRQ_Routine         /* defined in main.c  */
FIQ_Addr:       .word   FIQ_Routine         /* defined in main.c  */
                .word   0               /* rounds the vectors and ISR addresses to 64 bytes total  */

Reset_Handler: 
            /* Setup a stack for each mode - note that this only sets up a usable stack
            for User mode.   Also each mode is setup with interrupts initially disabled. */
              
             ldr   r0, =_stack_end
             msr   CPSR_c, #MODE_UND|I_BIT|F_BIT    /* Undefined Instruction Mode  */
             mov   sp, r0
             sub   r0, r0, #UND_STACK_SIZE
             msr   CPSR_c, #MODE_ABT|I_BIT|F_BIT    /* Abort Mode */
             mov   sp, r0
             sub   r0, r0, #ABT_STACK_SIZE
             msr   CPSR_c, #MODE_FIQ|I_BIT|F_BIT    /* FIQ Mode */
             mov   sp, r0   
               sub   r0, r0, #FIQ_STACK_SIZE
             msr   CPSR_c, #MODE_IRQ|I_BIT|F_BIT    /* IRQ Mode */
             mov   sp, r0
             sub   r0, r0, #IRQ_STACK_SIZE
             msr   CPSR_c, #MODE_SVC|I_BIT|F_BIT    /* Supervisor Mode */
             mov   sp, r0
             sub   r0, r0, #SVC_STACK_SIZE
             msr   CPSR_c, #MODE_SYS|I_BIT|F_BIT    /* User Mode */
             mov   sp, r0

            /* copy .data section (Copy from ROM to RAM) */
                ldr     R1, =_etext
                ldr     R2, =_data
                ldr     R3, =_edata
1:              cmp     R2, R3
                ldrlo   R0, [R1], #4
                strlo   R0, [R2], #4
                blo     1b

            /* Clear .bss section (Zero init)  */
                mov     R0, #0
                ldr     R1, =_bss_start
                ldr     R2, =_bss_end
2:            cmp     R1, R2
                strlo   R0, [R1], #4
                blo     2b

            /* Enter the C code  */
                b       main

.endfunc
.end
AtomSoft is offline  
Old 18th January 2009, 07:33 PM   #37
Default

Quote:
Originally Posted by AtomSoft View Post
Futz i have a feeling that your issue is Compiler specific. I was reading some info on the RealView MDK :
Nope. It's all caused by the crt.s startup code, which disables interrupts by default. (How stupid is that?) The guy who was helping me seemed to think it was perfectly normal to have startup code that disables interrupts. And I say, "Huh? Why? That seems crazy! Ok, whatever... Lets get em enabled then"

Quote:
try this as your startup code:
I won't even try it because it won't work. That one does the same thing.

To enable interrupts you add a piece of code like this (tho this one might not be for 2148).
Code:
/* Enable and disable functions "ripped" from a sample by R O Software.
* Copyright 2004, R O SoftWare
* No guarantees, warrantees, or promises, implied or otherwise.
* May be used for hobby or commercial purposes provided copyright
* notice remains intact. */

#include "VIClowlevel.h"

#define IRQ_MASK 0x00000080


static inline unsigned asm_get_cpsr(void)
{
unsigned long retval;

asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
return retval;
}


static inline void asm_set_cpsr(unsigned val)
{
asm volatile (" msr cpsr, %0" : /* no outputs */ : "r" (val) );
}


unsigned enableIRQ(void)
{
unsigned _cpsr;

_cpsr = asm_get_cpsr();
asm_set_cpsr(_cpsr & ~IRQ_MASK);
return _cpsr;
}


unsigned disableIRQ(void)
{
unsigned _cpsr;

_cpsr = asm_get_cpsr();
asm_set_cpsr(_cpsr | IRQ_MASK);
return _cpsr;
}


unsigned restoreIRQ(unsigned oldCPSR)
{
unsigned _cpsr;

_cpsr = asm_get_cpsr();
asm_set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
return _cpsr;
}
/* end of R O code */
and call enableIRQ() after init in main().
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 18th January 2009 at 08:25 PM.
futz is offline  
Old 18th January 2009, 08:55 PM   #38
Default

look at this startup script (from RealView(MDK)). I added the txt extension so i can upload it.
Attached Files
File Type: txt Startup.s.txt (14.5 KB, 8 views)

Last edited by AtomSoft; 18th January 2009 at 08:56 PM.
AtomSoft is offline  
Old 19th January 2009, 05:31 PM   #39
Default

well I don't know where it went, but the one thing that jumped out at me was that once it is an interrupt function the compiler should take interrupt controller if it has the support built in for the hardware so you should check the generated code for releasing the interrupt twice.

If not it is better to put it in a function call to handle the end of interrupt functionality so you only have to do it once.

I also do not remember now if you cleared the interrupt in the timer, this also needs to be done for it to trigger again.

If the processor itself has stopped running you need to check and see if it is in one of the error interrupt endless loops. While the standard compiler code defaults to this it would be a good idea to through out some indication that it has landed there if you are not going to handle them so you know it is time to reboot, or to let you know why it did if you have the watchdog running.

Dan
Ubergeek63 is offline  
Old 19th January 2009, 06:57 PM   #40
Default

Quote:
Originally Posted by Ubergeek63 View Post
well I don't know where it went, but the one thing that jumped out at me was that once it is an interrupt function the compiler should take interrupt controller if it has the support built in for the hardware so you should check the generated code for releasing the interrupt twice.

If not it is better to put it in a function call to handle the end of interrupt functionality so you only have to do it once.
I have no idea what you're talking about.


Quote:
I also do not remember now if you cleared the interrupt in the timer, this also needs to be done for it to trigger again.
Yes I did.
Code:
void IRQ_Routine(void)
{
    int i;
    IOSET0 = 0x30600000;        //4 LEDs blink
    for(i=0;i<0x0000ffff;i++);
    IOCLR0 = 0x30600000;
    T0IR = 0x01;                //clear interrupt
    VICVectAddr = 0;            //end of interrupt - dummy write
}

Quote:
If the processor itself has stopped running you need to check and see if it is in one of the error interrupt endless loops.
The processor is running fine. It just sits in my endless while(1) loop forever, waiting for that interrupt to fire.

Quote:
While the standard compiler code defaults to this it would be a good idea to through out some indication that it has landed there if you are not going to handle them so you know it is time to reboot, or to let you know why it did if you have the watchdog running.
Once again I have no idea what you mean by that. Do you mean that these stubs (I didn't write them - I think Jim Lynch did)
Code:
void FIQ_Routine(void){
    while (1) ; 
}
void SWI_Routine(void){
    while (1) ; 
}
void UNDEF_Routine(void) {
	while (1) ;	
}
should have something other than while(1) in them. I agree, but they're not getting hit. I've run the thing in the debugger enough to know for sure. Watchdog is not running.

manton (Mike) over at the SparkFun forum thread about this says the whole thing is because crt.s disables interrupts (for some whacked out reason that I can't comprehend). Here's the lines that do it (as far as I can see):
Code:
.set  I_BIT, 0x80		/* when I bit is set, IRQ is disabled (program status registers) */
.set  F_BIT, 0x40		/* when F bit is set, FIQ is disabled (program status registers) */

...

	msr   CPSR_c, #MODE_FIQ|I_BIT|F_BIT 	/* FIQ Mode */
	mov   sp, r0	
	sub   r0, r0, #FIQ_STACK_SIZE
	msr   CPSR_c, #MODE_IRQ|I_BIT|F_BIT 	/* IRQ Mode */
	mov   sp, r0
	sub   r0, r0, #IRQ_STACK_SIZE
He suggests adding that piece of code a few posts back to enable interrupts. I haven't got that to work yet, but haven't spent much time at it yet either.

The thing I don't get is why they think it's normal to have interrupts disabled in the startup code. That seems completely nutz to me. What good is an MCU with the interrupts disabled? It's crippled, IMHO. But whatever, if I can use that other piece of code to enable them then fine.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 21st January 2009 at 03:54 PM.
futz is offline  
Old 19th January 2009, 07:03 PM   #41
Default

all interrupts on a PIC are disabled until you enable them. I wish i had that board so i could help ya out but me just thinking and reading isnt helping much

Why not just comment this out:
Code:
.set  I_BIT, 0x80		/* when I bit is set, IRQ is disabled (program status registers) */
and see what that does. Instead of turning them on later do it so its always on.
AtomSoft is offline  
Old 19th January 2009, 07:11 PM   #42
Default

Quote:
Originally Posted by AtomSoft View Post
all interrupts on a PIC are disabled until you enable them.
I realize that. But all you have to do is diddle bits in a couple registers and they work. In this thing they're disabled. I diddle all the right registers and they should work, but they don't because somebody thought it made sense to make sure they couldn't work without doing something that should have already been done in the startup code. Weird!


Quote:
Why not just comment this out:
Code:
.set  I_BIT, 0x80		/* when I bit is set, IRQ is disabled (program status registers) */
and see what that does. Instead of turning them on later do it so its always on.
I'm thinking more like in this piece of crt.s code
Code:
    			msr   CPSR_c, #MODE_IRQ|I_BIT|F_BIT 	/* IRQ Mode */
    			mov   sp, r0
    			sub   r0, r0, #IRQ_STACK_SIZE
change it like this
Code:
    			msr   CPSR_c, #MODE_IRQ 	/* IRQ Mode */
    			mov   sp, r0
    			sub   r0, r0, #IRQ_STACK_SIZE
and do the same for the FIQ section.

EDIT: Well, that doesn't work. I'm obviously completely misunderstanding something. And none of the tutorials or other people's source code I've looked at mentions it.



For the life of me I can't understand why someone thought that was a good idea. I'm sure there's some good reason, but I sure don't know what it might be.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 19th January 2009 at 07:32 PM.
futz is offline  
Old 19th January 2009, 07:35 PM   #43
Default

This code pops the interrupt once each time the processor is reset, but never again. So I'm getting closer...
Code:
#include "LPC214x.h"
#define PLOCK 0x400
#define IRQ_MASK 0x00000080
void init(void);
void IRQ_Routine (void)   __attribute__ ((interrupt("IRQ")));
void FIQ_Routine (void)   __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void)   __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
unsigned enableIRQ(void);
unsigned disableIRQ(void);
unsigned restoreIRQ(unsigned oldCPSR);

unsigned int cp;

int main(void)
{
    int i;
    IODIR0 = 0x30600000;
    IOCLR0 = 0x30600000;                    //LEDs off
    init();
    T0TCR = 0x02;                           //reset counter
    T0IR = 0xff;
    T0MCR = 0x0003;                         //interrupt and reset on MR0
    T0MR0 = 0x0000ffff;                     //compare-hit count
    VICVectCntl0 = 0x00000024;              //use it for Timer 0 Interrupt:
    VICVectAddr0 = (unsigned)&IRQ_Routine;   //set interrupt vector in 0
    VICIntEnable = 0x00000010;              //enable TIMER0 interrupt
    T0TCR = 0x01;                           //enable Timer0
    cp = enableIRQ();
    
    while(1){
        i=0;
        i=1;
    }
}

void IRQ_Routine(void)
{
    int i;
    IOSET0 = 0x30600000;        //4 LEDs blink
    for(i=0;i<0x0000ffff;i++);
    IOCLR0 = 0x30600000;
    T0IR = 0x01;                //clear interrupt
    VICVectAddr0 = 0;           //end of interrupt - dummy write
}

void init(void)
{
    PLLCFG=0x24;                //set multiplier/divider values
    PLLFEED=0xaa;
    PLLFEED=0x55;
    PLLCON=0x01;                //enable PLL
    PLLFEED=0xaa;
    PLLFEED=0x55;
    while(!(PLLSTAT & PLOCK));  //wait for the PLL to lock to set frequency
    PLLCON=0x3;                 //connect the PLL as the clock source
    PLLFEED=0xaa;
    PLLFEED=0x55;
    MAMCR=0x02;                 //enable MAM
    MAMTIM=0x04;                //set number of clocks for flash memory fetch
    VPBDIV=0x01;                //set peripheral clock(pclk) to system clock(cclk)
}

void FIQ_Routine(void){
    while (1) ; 
}
void SWI_Routine(void){
    while (1) ; 
}
void UNDEF_Routine(void) {
	while (1) ;	
}
static inline unsigned asm_get_cpsr(void)
{
  unsigned long retval;
  asm volatile (" mrs  %0, cpsr" : "=r" (retval) : /* no inputs */  );
  return retval;
}

static inline void asm_set_cpsr(unsigned val)
{
  asm volatile (" msr  cpsr, %0" : /* no outputs */ : "r" (val)  );
}

unsigned enableIRQ(void)
{
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr(_cpsr & ~IRQ_MASK);
  return _cpsr;
}

unsigned disableIRQ(void)
{
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr(_cpsr | IRQ_MASK);
  return _cpsr;
}

unsigned restoreIRQ(unsigned oldCPSR)
{
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
  return _cpsr;
}
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 19th January 2009, 07:52 PM   #44
Default

i think its:
Code:
void IRQ_Routine(void)
{
    int i;
    IOSET0 = 0x30600000;        //4 LEDs blink
    for(i=0;i<0x0000ffff;i++);
    IOCLR0 = 0x30600000;
    T0IR = 0x01;                //clear interrupt
    VICVectAddr0 = 0;           //end of interrupt - dummy write
//The above bold changes the address again
}
try this:
Code:
void IRQ_Routine(void)
{
    int i;
    IOSET0 = 0x30600000;        //4 LEDs blink
    for(i=0;i<0x0000ffff;i++);
    IOCLR0 = 0x30600000;
    T0IR = 0x01;                //clear interrupt
    VICVectAddr = 0x0000;           //end of interrupt - dummy write
}
Read:
5.4.12 Vector Address register (VICVectAddr - 0xFFFF F030)
AtomSoft is offline  
Old 19th January 2009, 08:04 PM   #45
Default

Quote:
Originally Posted by AtomSoft View Post
i think its:
Oops! But that didn't fix it. Still doesn't work. Now, for no apparent reason, the debugger has decided it doesn't want to run the program anymore. Stupid thing.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 19th January 2009 at 08:21 PM.
futz is offline  
Reply

Tags
interrupts, lpc2148, match, timer, work

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
LPC2148 async serial baud rate confusion futz Micro Controllers 23 30th December 2008 03:48 PM
Best way for homemade E-Match SMUGangsta Chit-Chat 8 2nd November 2008 09:43 PM
Two circuits ground do not match xtcx Electronic Projects Design/Ideas/Reviews 3 24th December 2007 09:03 AM
I don't know why my Periodic ON-OFF Timer don't work. They are two CD4541. taotoon Electronic Projects Design/Ideas/Reviews 7 29th October 2007 03:10 AM
Need Help in Timer Interrupts, CCS C and PIC16F628A mysemcon2000 Micro Controllers 0 4th November 2006 02:12 PM



All times are GMT. The time now is 05:03 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker