查看: 556|回复: 1

[求助] 串口功能切换回普通的GPIO

[复制链接]

该用户从未签到

4

主题

8

帖子

0

注册会员

Rank: 2

积分
163
最后登录
2022-11-23
发表于 2022-11-22 10:12:08 | 显示全部楼层 |阅读模式
  使用的MCU为:S9KEAZN32AMLC,在初始化PTB0和PTB1为串口后,需要将PTB1切换回普通的GPIO功能,目前无法实现,PTB5使用没问题,请坛友帮忙看一下,感谢!
/*
* main implementation: use this 'C' sample to create your own application
*
*/




#include "derivative.h" /* include peripheral declarations SSKEAZN64M2 */
#include "gpio.h"
#include "ftm.h"
#include "UART.h"


FTM_Type* pFTM0 = (FTM_Type*)FTM0;
FTM_Type* pFTM1 = (FTM_Type*)FTM1;
FTM_Type* pFTM2 = (FTM_Type*)FTM2;




void FTM1_Task(void);


void Clk_Init();
void timer1_config();
void gpio_init();
void uart_com_init(void);


int main(void)
{
        /* Initialize Core Clock to 32MHz, Bus Clock to 16MHz  */
        Clk_Init();


        uart_com_init();
        gpio_init();




        timer1_config();


     while(1)
     {


     }


}






void Clk_Init()
{
ICS_C1|=ICS_C1_IRCLKEN_MASK  ;       /* Enable the internal reference clock*/
// ICS_C1 |= 0x06  ;
ICS_C3= 0x9B;                      /* Reference clock frequency = 31.25 kHz*/
while(!(ICS_S & ICS_S_LOCK_MASK)); /* Wait for PLL, running at 40 MHz (1280 * 31.25 kHz)      1024*31.25K = 32M  */
ICS_C2|=ICS_C2_BDIV(1);                /* BDIV=2, Bus clock = 20 MHz    16M */
ICS_S |= ICS_S_LOLS_MASK;                   /* Clear Loss of lock sticky bit */
}






void gpio_init()
{


        SIM_BASE_PTR->SCGC &= (~SIM_SCGC_UART0_MASK);
        CONFIG_PIN_AS_GPIO(PTB,PTB1,OUTPUT);
        OUTPUT_SET(PTB,PTB1);


        CONFIG_PIN_AS_GPIO(PTB,PTB5,OUTPUT);
        OUTPUT_SET(PTB,PTB5);
}




void timer1_config()
{
        FTM_ConfigType FTM1_Config={0};


        FTM1_Config.modulo=62499;
        FTM1_Config.clk_source=FTM_CLOCK_SYSTEMCLOCK;
        FTM1_Config.prescaler=FTM_CLOCK_PS_DIV128;
        FTM1_Config.mode=1;
        FTM1_Config.toie=1;


        FTM_SetCallback(pFTM1, FTM1_Task);
        FTM_Init(pFTM1,&FTM1_Config);
}




void uart_com_init(void)
{
        UART_ConfigType UART_Config={{0}};


        UART_Config.sctrl1settings.bits.bM=0;          /* 8 bit mode*/
        UART_Config.sctrl1settings.bits.bPe=0;        /* No hardware parity generation or checking*/
        UART_Config.bSbns=0;                                        /* One stop bit*/
        UART_Config.sctrl2settings.bits.bRe=1;        /* Enable Receiver*/
        UART_Config.sctrl2settings.bits.bTe=1;        /* Enable Transmitter*/
        UART_Config.sctrl2settings.bits.bRie=1;        /* Enable Receiver  interrupt */
        UART_Config.u32SysClkHz = 16000000;           /* Bus clock in Hz*/
        UART_Config.u32Baudrate = 19200;             /* UART baud rate */


//        UART_SetCallback(UART0, UART0_ISR);
        UART_Init(UART0,&UART_Config);
        PORT_PUEL |= 1<<8 ;
//        UART0->BDH |= UART_BDH_LBKDIE_MASK ;
        UART0->S2 |= UART_S2_BRK13_MASK ;
//        UART0->S2 |= UART_S2_LBKDE_MASK ;


//        UART_SendWait(UART0, test_Buff, 1);
        NVIC_SetPriority(UART0_IRQn,0);


}


void FTM1_Task(void)
{
        FTM_ClrOverFlowFlag(pFTM1);


        static uint8_t Cnt_1s = 0 ;
        Cnt_1s ++ ;


        if(Cnt_1s == 2)
        {
                Cnt_1s = 0;
                OUTPUT_TOGGLE(PTB,PTB1);
                OUTPUT_TOGGLE(PTB,PTB5);
        }
}


我知道答案 目前已有1人回答
回复

使用道具 举报

该用户从未签到

0

主题

2

帖子

0

注册会员

Rank: 2

积分
122
最后登录
2024-3-27
发表于 2022-12-1 14:41:57 | 显示全部楼层
解决了吗?我也碰到相似的问题
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2024-4-26 05:58 , Processed in 0.108441 second(s), 21 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表