Forum: Mikrocontroller und Digitale Elektronik Frage zu LPC1114 - GPIO


von M. G. (ixil96)


Lesenswert?

Hallo,

ich mache gerade die ersten Schritte mit dem LPCXpresso Board LPC1114 
und habe das Beispiel "LPCX_cmsis2_blinky" importiert.

Wenn ich nun zusätzlich eine LED am PORT0, Bit10 ansteuern möchte, 
leuchtet die LED nur ganz schwach. Der GPIO Pin wird lt. Oszi permanent 
ON/OFF geschaltet.

Kann mir bitte jemand sagen, warum das so ist?

Mit GPIOSetDir( 0, 10, 1 ); schalte ich Pin10 auf Ausgang
anschließend in der while-Schleife alle halben Sekunden
mit GPIOSetValue(0,10,1); bzw. GPIOSetValue(0,10,0); auf On bzw. Off

Hier mein Code:
1
//*****************************************************************************
2
//   +--+
3
//   | ++----+
4
//   +-++    |
5
//     |     |
6
//   +-+--+  |
7
//   | +--+--+
8
//   +----+    Copyright (c) 2010-11 Code Red Technologies Ltd.
9
//
10
// LED flashing Timer16 application for LPCXPresso1114 board
11
//
12
// Software License Agreement
13
//
14
// The software is owned by Code Red Technologies and/or its suppliers, and is
15
// protected under applicable copyright laws.  All rights are reserved.  Any
16
// use in violation of the foregoing restrictions may subject the user to criminal
17
// sanctions under applicable laws, as well as to civil liability for the breach
18
// of the terms and conditions of this license.
19
//
20
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
21
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
22
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
23
// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
24
// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
25
// CODE RED TECHNOLOGIES LTD.
26
//
27
//*****************************************************************************
28
29
30
#include "LPC11xx.h"                        /* LPC11xx definitions */
31
#include "timer16.h"
32
#include "clkconfig.h"
33
#include "gpio.h"
34
35
#include <cr_section_macros.h>
36
#include <NXP/crp.h>
37
38
// Variable to store CRP value in. Will be placed automatically
39
// by the linker when "Enable Code Read Protect" selected.
40
// See crp.h header for more information
41
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
42
43
// LPCXpresso processor card LED
44
#define LED_PORT   0    // Port for led
45
#define LED_BIT   7    // Bit on port for led
46
#define LED_ON     1    // Level to set port to turn on led
47
#define LED_OFF   0    // Level to set port to turn off led
48
49
extern volatile uint32_t timer16_0_counter;
50
51
int main (void)
52
{
53
  GPIOInit();
54
55
    // Initialise Timer16_0 to tick at rate of 1/2000th of second.
56
  // Note that as this is a 16 bit timer, the maximum count we can
57
  // load into timer is 0xFFFF, or 65535. Default clock speed
58
  // set up by CMSIS SystemInit function - SystemCoreClock - is
59
  // 48MHz or 48000000 Hz. Dividing this by 2000 is 24000 which is
60
  // within appropriate timer16 maximum. This could be extended
61
  // if timer routine extended to make use of Prescale Counter register
62
  // Note by default LPC_SYSCON->SYSAHBCLKDIV is 1.
63
  init_timer16(0, (SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/2000 );
64
65
  // Initialise counter that counts Timer16_0 ticks
66
  timer16_0_counter = 0;
67
68
  //Enable Timer16_0
69
  enable_timer16(0);
70
71
  // Set port for LED to output
72
  GPIOSetDir( LED_PORT, LED_BIT, 1 );
73
  GPIOSetDir( 0, 10, 1 );  // Set PORT0 direction Bit10 to output
74
75
  while (1)                                /* Loop forever */
76
  {
77
78
  // LED is on for 1st half-second
79
  if ( (timer16_0_counter > 0) && (timer16_0_counter <= 1000) )
80
  {
81
    GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
82
    GPIOSetValue(0,10,1);  // PORT0 Bit10 High
83
  }
84
85
  // LED is off for 2nd half-second
86
  if ( (timer16_0_counter > 1000) && (timer16_0_counter <= 2000) )
87
  {
88
    GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
89
    GPIOSetValue(0,10,0);  // PORT0 Bit10 Low
90
  }
91
92
  // Reset counter
93
  else if ( timer16_0_counter > 2000 )
94
  {
95
    timer16_0_counter = 0;
96
  }
97
  }
98
}

von Jojo S. (Gast)


Lesenswert?

Und wenn du die LED statt über den Portpin zu schalten direkt auf 3,3 V 
oder GND klemmst? Wie gross ist der Vorwiderstand?

von M. G. (ixil96)


Lesenswert?

Hab ich schon versucht! Das passt dann! Vorwiderstand (rote LED) = 470 
Ohm.

von M. G. (ixil96)


Lesenswert?

Ah...ich glaub hier hängt der SWCLK drauf...
Ich werde einen anderen Portpin versuchen!

von M. G. (ixil96)


Lesenswert?

m. g. schrieb:
> Ah...ich glaub hier hängt der SWCLK drauf...
> Ich werde einen anderen Portpin versuchen!

Genau das wars!
Ich hab blöderweise den SWCLK-Pin vom LPC-Link erwischt!

von Jojo S. (Gast)


Lesenswert?

könnte man in IOCON_SWCLK_PIO0_10 umkonfigurieren, aber das ist 
natürlich ungünstig weil man sich dann den Debugger abklemmt.
Eine andere Falle gibt es noch bei den I2C SDA/SCL Pins: die haben 
keinen internen PullUp. Das kann auch mal einige Zeit Fehlersuche 
kosten.

von M. G. (ixil96)


Lesenswert?

Jojo S. schrieb:
> könnte man in IOCON_SWCLK_PIO0_10 umkonfigurieren, aber das ist
> natürlich ungünstig weil man sich dann den Debugger abklemmt.
> Eine andere Falle gibt es noch bei den I2C SDA/SCL Pins: die haben
> keinen internen PullUp. Das kann auch mal einige Zeit Fehlersuche
> kosten.

Danke für den Hinweis!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.