在线时间19 小时
UID3874134
注册时间2022-9-23
NXP金币12
该用户从未签到
注册会员
- 积分
- 163
- 最后登录
- 2022-11-23
|
使用的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);
}
}
|
|