-1

I'm using LPC1114FN28/102 and its user manual can be found here.
I'm using my original macro to develop programs for that microcontroller with nasm.

I am trying to blink a LED connected to general I/O port (I don't care much about the interval of blinking here).

When I use PIO0_3 with this code, it works well.

%include "lpc1114_macro.inc"

start:
; Initial SP value
    dd 0x10000FF0
; reset
    dd reset - start + 1
; NMI
    dd nmi - start + 1
; HardFault
    dd hardfault - start + 1
; reserved
    dd 0
    dd 0
    dd 0
    dd -(0x10000FF0 + (reset - start + 1) + (nmi - start + 1) + (hardfault - start + 1))
    dd 0
    dd 0
    dd 0
; SVCall
    dd svcall - start + 1
; reserved
    dd 0
    dd 0
; PendSV
    dd pendsv - start + 1
; SysTick
    dd systick - start + 1
; IRQn
    dd irq0 - start + 1
    dd irq1 - start + 1
    dd irq2 - start + 1
    dd irq3 - start + 1
    dd irq4 - start + 1
    dd irq5 - start + 1
    dd irq6 - start + 1
    dd irq7 - start + 1
    dd irq8 - start + 1
    dd irq9 - start + 1
    dd irq10 - start + 1
    dd irq11 - start + 1
    dd irq12 - start + 1
    dd irq13 - start + 1
    dd irq14 - start + 1
    dd irq15 - start + 1
    dd irq16 - start + 1
    dd irq17 - start + 1
    dd irq18 - start + 1
    dd irq19 - start + 1
    dd irq20 - start + 1
    dd irq21 - start + 1
    dd irq22 - start + 1
    dd irq23 - start + 1
    dd irq24 - start + 1
    dd irq25 - start + 1
    dd irq26 - start + 1
    dd irq27 - start + 1
    dd irq28 - start + 1
    dd irq29 - start + 1
    dd irq30 - start + 1
    dd irq31 - start + 1
    times (63 - 48 + 1) dd 0

nmi:
hardfault:
svcall:
pendsv:
systick:
irq0:
irq1:
irq2:
irq3:
irq4:
irq5:
irq6:
irq7:
irq8:
irq9:
irq10:
irq11:
irq12:
irq13:
irq14:
irq15:
irq16:
irq17:
irq18:
irq19:
irq20:
irq21:
irq22:
irq23:
irq24:
irq25:
irq26:
irq27:
irq28:
irq29:
irq30:
irq31:
    BX LR

reset:
    ; disable pullup / pulldown on PIO0_3
    LDR R0, iocon_pio0_3_addr
    MOVS R1, #0xC0
    STR R1, [R0, #0]
    ; set PIO0_3 as output
    LDR R0, pio0_dir_addr
    MOVS R1, #1
    LSLS R1, #3
    STR R1, [R0, #0]
    ; output to PIO0_3
    LDR R0, pio0_3_addr
mainloop:
    MOVS R1, #1
    LSLS R1, #3
    STR R1, [R0, #0]
    BL busyloop
    MOVS R1, #0
    STR R1, [R0, #0]
    BL busyloop
    B mainloop

    align 4
iocon_pio0_3_addr:
    dd 0x4004402C
pio0_3_addr:
    dd 0x50000020
pio0_dir_addr:
    dd 0x50008000

busyloop:
    PUSH {R0}
    LDR R0, busyloop_num
busyloop_loop:
    SUBS R0, #1
    BPL busyloop_loop
    POP {R0}
    BX LR
    align 4
busyloop_num:
    dd 1500000

    align 4

In the other hand, when I try to use PIO0_11 with this code, which has only a little change from previous code, the port doesn't seem working and is in high-impedance state.

%include "lpc1114_macro.inc"

start:
; Initial SP value
    dd 0x10000FF0
; reset
    dd reset - start + 1
; NMI
    dd nmi - start + 1
; HardFault
    dd hardfault - start + 1
; reserved
    dd 0
    dd 0
    dd 0
    dd -(0x10000FF0 + (reset - start + 1) + (nmi - start + 1) + (hardfault - start + 1))
    dd 0
    dd 0
    dd 0
; SVCall
    dd svcall - start + 1
; reserved
    dd 0
    dd 0
; PendSV
    dd pendsv - start + 1
; SysTick
    dd systick - start + 1
; IRQn
    dd irq0 - start + 1
    dd irq1 - start + 1
    dd irq2 - start + 1
    dd irq3 - start + 1
    dd irq4 - start + 1
    dd irq5 - start + 1
    dd irq6 - start + 1
    dd irq7 - start + 1
    dd irq8 - start + 1
    dd irq9 - start + 1
    dd irq10 - start + 1
    dd irq11 - start + 1
    dd irq12 - start + 1
    dd irq13 - start + 1
    dd irq14 - start + 1
    dd irq15 - start + 1
    dd irq16 - start + 1
    dd irq17 - start + 1
    dd irq18 - start + 1
    dd irq19 - start + 1
    dd irq20 - start + 1
    dd irq21 - start + 1
    dd irq22 - start + 1
    dd irq23 - start + 1
    dd irq24 - start + 1
    dd irq25 - start + 1
    dd irq26 - start + 1
    dd irq27 - start + 1
    dd irq28 - start + 1
    dd irq29 - start + 1
    dd irq30 - start + 1
    dd irq31 - start + 1
    times (63 - 48 + 1) dd 0

nmi:
hardfault:
svcall:
pendsv:
systick:
irq0:
irq1:
irq2:
irq3:
irq4:
irq5:
irq6:
irq7:
irq8:
irq9:
irq10:
irq11:
irq12:
irq13:
irq14:
irq15:
irq16:
irq17:
irq18:
irq19:
irq20:
irq21:
irq22:
irq23:
irq24:
irq25:
irq26:
irq27:
irq28:
irq29:
irq30:
irq31:
    BX LR

reset:
    ; disable pullup / pulldown on PIO0_11
    LDR R0, iocon_pio0_11_addr
    MOVS R1, #0xC1
    STR R1, [R0, #0]
    ; set PIO0_11 as output
    LDR R0, pio0_dir_addr
    MOVS R1, #1
    LSLS R1, #11
    STR R1, [R0, #0]
    ; output to PIO0_11
    LDR R0, pio0_11_addr
mainloop:
    MOVS R1, #1
    LSLS R1, #11
    STR R1, [R0, #0]
    BL busyloop
    MOVS R1, #0
    STR R1, [R0, #0]
    BL busyloop
    B mainloop

    align 4
iocon_pio0_11_addr:
    dd 0x40044074
pio0_11_addr:
    dd 0x50002000
pio0_dir_addr:
    dd 0x50008000

busyloop:
    PUSH {R0}
    LDR R0, busyloop_num
busyloop_loop:
    SUBS R0, #1
    BPL busyloop_loop
    POP {R0}
    BX LR
    align 4
busyloop_num:
    dd 1500000

    align 4

Why the port isn't working and what I should do to overcome this issue?

I think the function selecting for the port isn't working well because it was successful with PIO0_9 and unsuccessful with PIO0_10.

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
  • From a quick glance, you did everything right. What happens if you change `pio0_11_addr` to `0x50003ffc` (that affects all pins)? – Jester Nov 14 '15 at 01:57
  • The condition din't change. Note that the pin is hi-impedance, not high nor low. – MikeCAT Nov 14 '15 at 02:03

1 Answers1

1

The clock for I/O configuration block has to be enabled before accessing IOCON registers.

This code worked:

%include "lpc1114_macro.inc"

start:
; Initial SP value
    dd 0x10000FF0
; reset
    dd reset - start + 1
; NMI
    dd nmi - start + 1
; HardFault
    dd hardfault - start + 1
; reserved
    dd 0
    dd 0
    dd 0
    dd -(0x10000FF0 + (reset - start + 1) + (nmi - start + 1) + (hardfault - start + 1))
    dd 0
    dd 0
    dd 0
; SVCall
    dd svcall - start + 1
; reserved
    dd 0
    dd 0
; PendSV
    dd pendsv - start + 1
; SysTick
    dd systick - start + 1
; IRQn
    dd irq0 - start + 1
    dd irq1 - start + 1
    dd irq2 - start + 1
    dd irq3 - start + 1
    dd irq4 - start + 1
    dd irq5 - start + 1
    dd irq6 - start + 1
    dd irq7 - start + 1
    dd irq8 - start + 1
    dd irq9 - start + 1
    dd irq10 - start + 1
    dd irq11 - start + 1
    dd irq12 - start + 1
    dd irq13 - start + 1
    dd irq14 - start + 1
    dd irq15 - start + 1
    dd irq16 - start + 1
    dd irq17 - start + 1
    dd irq18 - start + 1
    dd irq19 - start + 1
    dd irq20 - start + 1
    dd irq21 - start + 1
    dd irq22 - start + 1
    dd irq23 - start + 1
    dd irq24 - start + 1
    dd irq25 - start + 1
    dd irq26 - start + 1
    dd irq27 - start + 1
    dd irq28 - start + 1
    dd irq29 - start + 1
    dd irq30 - start + 1
    dd irq31 - start + 1
    times (63 - 48 + 1) dd 0

nmi:
hardfault:
svcall:
pendsv:
systick:
irq0:
irq1:
irq2:
irq3:
irq4:
irq5:
irq6:
irq7:
irq8:
irq9:
irq10:
irq11:
irq12:
irq13:
irq14:
irq15:
irq16:
irq17:
irq18:
irq19:
irq20:
irq21:
irq22:
irq23:
irq24:
irq25:
irq26:
irq27:
irq28:
irq29:
irq30:
irq31:
    BX LR

reset:
    ; enable clock for IOCON
    LDR R0, sysahbclkctrl_addr
    LDR R1, [R0]
    MOVS R2, #1
    LSLS R2, #16
    ORRS R1, R2
    STR R1, [R0]
    ; disable pullup / pulldown on PIO0_11
    LDR R0, iocon_pio0_11_addr
    MOVS R1, #0xC1
    STR R1, [R0, #0]
    ; disable clock for IOCON
    LDR R0, sysahbclkctrl_addr
    LDR R1, [R0]
    MOVS R2, #1
    LSLS R2, #16
    BICS R1, R2
    STR R1, [R0]
    ; set PIO0_11 as output
    LDR R0, pio0_dir_addr
    MOVS R1, #1
    LSLS R1, #11
    STR R1, [R0, #0]
    ; output to PIO0_11
    LDR R0, pio0_11_addr
mainloop:
    MOVS R1, #1
    LSLS R1, #11
    STR R1, [R0, #0]
    BL busyloop
    MOVS R1, #0
    STR R1, [R0, #0]
    BL busyloop
    B mainloop

    align 4
sysahbclkctrl_addr:
    dd 0x40048080
iocon_pio0_11_addr:
    dd 0x40044074
pio0_11_addr:
    dd 0x50002000
pio0_dir_addr:
    dd 0x50008000

busyloop:
    PUSH {R0}
    LDR R0, busyloop_num
busyloop_loop:
    SUBS R0, #1
    BPL busyloop_loop
    POP {R0}
    BX LR
    align 4
busyloop_num:
    dd 1500000

    align 4
MikeCAT
  • 73,922
  • 11
  • 45
  • 70