本帖最后由 suncat0504 于 2024-7-8 23:12 编辑
为了后面能正常SPI接口,本次实验测试LPC54114开发板的SPI外设。先看下这块开发板的电路图和元件布局图: 原理图: 有热心伙伴提供了资料,也从论坛里找到很多相关的资料。但看了资料后,总感觉有写出入,不完全匹配。不管怎么说,先根据PCB板子上的印字提示,测测看吧。
在CN6上提供的排针接口中,按照印制板上的注释,有如下配置: PIO0.11 - SCLK PIO0.13 - MISO PIO0.12 - MOSI PIO0.14 - SS 为了验证接口与单片机的实际输出是否一致,先以模拟方式,使用流水灯模式依次翻转输出。使用之前连接了TF显示屏的例程,在那个例程基础上进行改造。 初始化部分的代码: - void BOARD_InitPins(void) {
- /* Enables the clock for the IOCON block. 0 = Disable; 1 = Enable.: 0x01u */
- CLOCK_EnableClock(kCLOCK_Iocon);
- /* Enables the clock for the GPIO1 module */
- CLOCK_EnableClock(kCLOCK_Gpio1); // 允许Port1时钟
- CLOCK_EnableClock(kCLOCK_Gpio0); // 允许Port0时钟
- gpio_pin_config_t LED_GREEN_config = {
- .pinDirection = kGPIO_DigitalOutput,
- .outputLogic = 0U
- };
- /* Initialize GPIO functionality on pin PIO1_10 (pin 30) */
- //GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_PORT, BOARD_LED_GREEN_PIN, &LED_GREEN_config);
- //GPIO_PinInit(BOARD_LED_GREEN_GPIO, PORT01, PIN01_0 | PIN01_1 | PIN01_2 | PIN01_3 | PIN01_4, &LED_GREEN_config);
-
- GPIO_PinInit(GPIO, PORT01, PIN01_0, &LED_GREEN_config);
- GPIO_PinInit(GPIO, PORT01, PIN01_1, &LED_GREEN_config);
- GPIO_PinInit(GPIO, PORT01, PIN01_2, &LED_GREEN_config);
- GPIO_PinInit(GPIO, PORT01, PIN01_3, &LED_GREEN_config);
- GPIO_PinInit(GPIO, PORT01, PIN01_4, &LED_GREEN_config);
- GPIO_PinInit(GPIO, PORT01, PIN01_5, &LED_GREEN_config);
- IOCON->PIO[0][15] = ((IOCON->PIO[0][15] &
- /* Mask bits to zero which are setting */
- (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_MODE_MASK | IOCON_PIO_DIGIMODE_MASK)))
- /* Selects pin function.
- * : PORT015 (pin 50) is configured as SWO. */
- | IOCON_PIO_FUNC(PIO015_FUNC_ALT2)
- /* Selects function mode (on-chip pull-up/pull-down resistor control).
- * : Inactive.
- * Inactive (no pull-down/pull-up resistor enabled). */
- | IOCON_PIO_MODE(PIO015_MODE_INACTIVE)
- /* Select Analog/Digital mode.
- * : Digital mode. */
- | IOCON_PIO_DIGIMODE(PIO015_DIGIMODE_DIGITAL));
- const uint32_t LED_GREEN = (/* Pin is configured as PIO1_10 */
- IOCON_PIO_FUNC0 |
- /* Selects pull-up function */
- IOCON_PIO_MODE_PULLUP |
- /* Input function is not inverted */
- IOCON_PIO_INV_DI |
- /* Enables digital function */
- IOCON_PIO_DIGITAL_EN |
- /* Input filter disabled */
- IOCON_PIO_INPFILT_OFF |
- /* Standard mode, output slew rate control is enabled */
- IOCON_PIO_SLEW_STANDARD |
- /* Open drain is disabled */
- IOCON_PIO_OPENDRAIN_DI);
-
- /* PORT1 PIN10 (coords: 30) is configured as PIO1_10 */
- IOCON_PinMuxSet(IOCON, BOARD_LED_GREEN_PORT, BOARD_LED_GREEN_PIN, LED_GREEN);
- // CN6的SPI输出口
- GPIO_PinInit(GPIO, PORT00, PIN00_11, &LED_GREEN_config); // SCLK
- GPIO_PinInit(GPIO, PORT00, PIN00_12, &LED_GREEN_config); // MOSI
- GPIO_PinInit(GPIO, PORT00, PIN00_13, &LED_GREEN_config); // MISO
- GPIO_PinInit(GPIO, PORT00, PIN00_14, &LED_GREEN_config); // SS
- }
复制代码主程序部分: - <blockquote>uint32_t pins[] = {PIN00_11, PIN00_12, PIN00_13, PIN00_14};
复制代码
编译程序,下载运行: 是由视频转的,因为图像尺寸的缘故,转化的图片比较小。但可以看到4个LED依次点亮和灭掉。说明PCB上标记的端口没问题。
|