前言

本专栏会以NXP S32K144为依托,记录各个模块的原理和实现方法。
首先第一个模块都是以PORT模块开始,以此模块制定目标:
以按键控制对应的LED灯,按键不按时,对应LED灯熄灭,当按下按键时对应LED灯点亮。
为了实现这个功能,需要用到PORT和DIO模块,PORT模块是用于配置port端口,DIO模块是用于配置pin脚。

电路原理图

先上原理图。
Alt
从LED原理图可知,电路有4个LED灯,LED灯一端连接电源VCC_MCU。
Alt
从按键原理图可知,电路有3个按键,不按按键时按键接地,按下按键时,按键另一端和VCC_MCU连接,使按键产生电压。
Alt
从LED原理图可知,可得到以下信息:

LED灯 MCU端口
LEDG(reen) PTD16
LEDR(ed) PTD15
LEDY(ellow) PTD1
LEDB(lue) PTD0

Alt
Alt
从LED原理图可知,可得到以下信息:

KEY按键 MCU端口
KEY1 PTC12
KEY2 PTC13
KEY3 PTB2

EB Tresos配置

debug 设置

为了能够使用debug能力,JTAG pin脚需要在Port driver中配置。pin脚包括JTAG_TDO, JTAG_TMS, Reset_b。
具体配置如下:

Alt

Alt
Alt
Alt
Alt

KEY 和LED设置

Alt由于LED灯是被控制设备,其方向需设置为OUT。

Alt

Alt

DIO设置

Dio Port Id,映射了序号和Port端口关系

Dio Port Id Port端口
0 PortA
1 PortB
2 PortC
3 PortD

Dio Channel Id,映射了t特定Port端口和Pin脚关系
Each of the 5 ports have a number of 32 pins, such that the pins are allocated to ports
like below:
• 0-31 -> PORTA
• 32-63 -> PORTB
• 64-95 -> PORTC
• 96-127 -> PORTD
• 128-159 -> PORTE

LED 在DIO设置

LED Green灯对应端口为Port16,其在DIO模块的设置方法如下:
Alt

KEY 在DIO设置

KEY2对应端口为PortC 13,其在DIO模块的设置方法如下:
Alt

Alt

驱动代码


/*
 * main implementation: use this 'C' sample to create your own application
 *
 */

#include "Mcu.h"
#include "Mcu_Cfg.h"
#include "Port.h"
#include "Port_Cfg.h"
#include "Dio.h"
#include "Dio_Cfg.h"


/**
* @brief        Main function of the example
* @details      Initializez the used drivers and uses the Icu
*               and Dio drivers to toggle a LED on a push button
*/
int main(void)
{
    uint8 RET = 0;
    /* Initialize the Mcu driver */
    Mcu_Init(&McuModuleConfiguration);

    Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
    while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
    {
        /* Busy wait until the System PLL is locked */
    }

    Mcu_DistributePllClock();
#endif
    Mcu_SetMode(McuModeSettingConf_0);
    /* Initialize all pins using the Port driver */
    Port_Init(&PortConfigSet);
    

    while (1)
    {

        RET = Dio_ReadChannel(77);//PTC13

        if(RET == 1)//PRESSED
        {
            Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED_G, (Dio_LevelType)STD_LOW);//OFF
            
        }
        else
        {
            Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_LED_G, (Dio_LevelType)STD_HIGH);//OFF
            
        }

    }
    while(1);
    return (0U);
}

总结

本节按照原理图,EB配置和驱动代码顺序,详细论述了如何实现PORT驱动的实验目标。

作者:OnlyMars

物联沃分享整理
物联沃-IOTWORD物联网 » S32K144 PORT详解

发表回复