LPC18S37 引脚配置

问题描述

我在定制板上有 LPC18S37(TFBGA100)。我需要一些基本的引脚配置帮助。 为了防止在多个文件之间来回切换,我从工作应用程序的引脚配置中提取了一段代码(见下文)。

LPC18xx.h

/* BSP */
#include "LPC18xx.h"

#define LPC_SCU_BASE              0x40086000
#define LPC_GPIO_PORT             ((LPC_GPIO_PORT_Type      *) LPC_GPIO_PORT_BASE)

/** Port offset deFinition */
#define PORT_OFFSET     0x80
/** Pin offset deFinition */
#define PIN_OFFSET      0x04

/* Pin modes */
#define MD_PUP  (0x0<<3)
#define MD_BUK  (0x1<<3)
#define MD_PLN  (0x2<<3)
#define MD_PDN  (0x3<<3)
#define MD_EHS  (0x1<<5)
#define MD_EZI  (0x1<<6)
#define MD_ZI   (0x1<<7)
#define MD_EHD0 (0x1<<8)
#define MD_EHD1 (0x1<<8)
#define MD_PLN_FAST (MD_PLN | MD_EZI | MD_ZI | MD_EHS)
// 0xF0

/* Pin function */
#define FUNC0           0x0             /** Function 0  */
#define FUNC1           0x1             /** Function 1  */
#define FUNC2           0x2             /** Function 2  */
#define FUNC3           0x3             /** Function 3  */
#define FUNC4           0x4
#define FUNC5           0x5
#define FUNC6           0x6
#define FUNC7           0x7

#define LPC_SCU_PIN(po,pi)   (*(volatile int         *) (LPC_SCU_BASE + ((po) * 0x80) + ((pi) * 0x4))    )
#define LPC_SCU_CLK(c)        (*(volatile int         *) (LPC_SCU_BASE + 0xC00 + ((c) * 0x4))    )

/*********************************************************************//**
 * @brief       Configure pin function
 * @param[in]   port    Port number,should be: 0..15
 * @param[in]   pin     Pin number,should be: 0..31
 * @param[in]   mode    Pin mode,should be:
 *                  - MD_PUP    :Pull-up enabled
 *                  - MD_BUK    :Plain input
 *                  - MD_PLN    :Repeater mode
 *                  - MD_PDN    :Pull-down enabled
 * @param[in]   func    Function mode,should be:
 *                  - FUNC0     :Function 0
 *                  - FUNC1     :Function 1
 *                  - FUNC2     :Function 2
 *                  - FUNC3     :Function 3
 * @return      None
 **********************************************************************/
void scu_pinmux(uint8_t port,uint8_t pin,uint8_t mode,uint8_t func)
{
  uint32_t * scu_base=(uint32_t*)(LPC_SCU_BASE);
  scu_base[(PORT_OFFSET*port+PIN_OFFSET*pin)/4]=mode+func;
} /* scu_pinmux */
void GPIO_SetDir(uint8_t portNum,uint32_t bitValue,uint8_t dir)
{
  if (dir)
  {
    LPC_GPIO_PORT->DIR[portNum] |= bitValue;
  } else
    {
      LPC_GPIO_PORT->DIR[portNum] &= ~bitValue;
    }
}


#define D3_SCU_CONfig   0xD,14,MD_PLN,FUNC4

#define D3_SCU_PIN 14
#define D3_SCU_PORT 0xD
#define D3_GPIO_PORT    6
#define D3_GPIO_PIN     28
#define D3_GPIO_MASK    (1 << D3_GPIO_PIN)

/* 
  This is where we set pins in the application.
*/
scu_pinmux(D3_SCU_CONfig);
GPIO_SetDir(D3_GPIO_PORT,D3_GPIO_MASK,1);

在引脚描述的数据表中说;

On the LPC185x/3x/2x/1x,digital pins are grouped into 16 ports,named P0 to P9 and PA to PF,with up to 20 pins used per port. Each digital pin can support up to eight different digital functions,including General-Purpose I/O (GPIO),selectable through the SCU registers. The pin name is not indicative of the GPIO port assigned to it.

这个描述不是我习惯于与我以前的设备(LPC1769)进行比较的,没有这样的寄存器叫做 SCU。

特别是我在 SCU_PIN(或 PORT)和 GPIO_PIN(或 PORT)之间感到困惑。虽然我能理解 GPIO_PIN,但 SCU_PIN 却让我非常困惑。

enter image description here

我需要将 GPIO3[5](bga 引脚输出为 F8)设置为 LED 的输出。 那么我应该如何相应地设置这些定义?

#define D3_SCU_CONfig   0xD,FUNC4

#define D3_SCU_PIN 14
#define D3_SCU_PORT 0xD
#define D3_GPIO_PORT    6
#define D3_GPIO_PIN     28
#define D3_GPIO_MASK    (1 << D3_GPIO_PIN)

所以,我想知道数字 28 作为 GPIO_PIN 是从哪里来的,如上所示?! 高度赞赏有关此设备上的引脚定义的任何指针。

解决方法

这是我自己的答案,可能需要同样的说明;

作为我基于 SCU 和 GPIO 角色混淆的问题,我用正确的数字放置了定义,以便使 LED 亮起和熄灭,包括引脚的初始化。请使用我上面原始帖子中的代码来了解设备要求,并通过下面的代码完成 LED 引脚部分;

/*******************************************************************************
 * LED on the pin; P6[9]_/GPIO3[5]/NC/NC/EXTBUS_nDYCS0
 ******************************************************************************/
#define D3_SCU_CONFIG   0x6,6,MD_PLN,FUNC4
/* P6[9] */
#define D3_SCU_PORT     0x6
#define D3_SCU_PIN      9
/* GPIO3[5] */
#define D3_GPIO_PORT    3
#define D3_GPIO_PIN     5
#define D3_GPIO_MASK    (1 << D3_GPIO_PIN)

/* 
  This is how we set pins in the application.
*/
/* Init */
scu_pinmux(D3_SCU_CONFIG);
GPIO_SetDir(D3_GPIO_PORT,D3_GPIO_MASK,1);
/* Use in the application */
/* Turn the LED OFF */
GPIO_ClearValue(D3_GPIO_PORT,D3_GPIO_MASK);
/* Turn the LED ON */
GPIO_SetValue(D3_GPIO_PORT,D3_GPIO_MASK);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...