PT32Y003
产品介绍:PT32Y003x 系列使用高性能低功耗的 Cortex™-M0 32位内核,最高工作频率可达48MHz,支持1.8V至5.5V工作电压及-40℃至+85℃的温度范围。内置多达16K 字节的MTP存储器、2K字节的SRAM和128字节EEPROM。集成多功能复用的I/O端口及丰富的外设功能:包含1个多达12通道的12位ADC,1个高级定时器,2个基本16位定时器和1个低功耗定时器。还集成1路SPI接口,1路I2C接口和2路UART 接口。支持两种低功耗模式。主要特色:超高性价比,低功耗(典型深度休眠待机功耗为3uA),主频最高到48MHz,强大的安全与保密性能,多种封装外型支持,全套开发板,代码示例支持, ESD(HBM):8KV,EFT: 4KV。
主要应用:PT32Y003x系列产品适用于多种应用场合:- 工业应用:
[*]电机控制、医疗保健、小家电及电动工具
[*]住宅、楼宇和城市自动化、变频器、打印机等等
- 消费类电子产品:
[*]可穿戴设备、智能家居
[*]充电器、无线充、锂电池充电、仪表显示
[*]游戏外设、四轴飞行器、无线耳机
[*]玩具及干电池类快消品等市场
SDK请参考! V1.6版本 ,如有新版本会陆续更新
#技术资源# ADC 代码分享
/******************************************************************************
* @file PT32Y003x_adc.c
* @author应用开发团队
* @version V1.0.0
* @date 2022/9/1
* @brief This file provides firmware functions to manage the following
* functionalities of the ADC peripheral:
* + Initialization and Configuration
* + Interrupts and flags management
*
******************************************************************************
* @attention
*
*
*****************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "PT32Y003x_adc.h"
/** @defgroup ADC
* @brief ADC driver modules
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define Init_CR1_MASK (u32)0xFFC0F481
#define Init_CR2_MASK (u32)0xFF00FFFF
#define SetSampleTime_CR2_MASK (u32)0xFFFF00FF
/***********************
**1. 把AGENT_H 定义成静态变量(是除以1000之后的值 最后直接相加即可 )
*******************/
static s16 AGENT_H_stc_div1000=0;
static uint8_t AGENT_ID_stc_ENABLE=0; /**为0未设置,为1已设置,后面要用**/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @briefInitializes the ADCx peripheral according to the specified parameters
* in the ADC_InitStruct.
* @NOTE This function is used to configure the global features of the ADC (
* Resolution, Data Alignment, continuous mode activation, External
* trigger source and edge, Sequence Scan Direction).
* @paramADCx: where x can be 1 to select the ADC peripheral.
* @paramADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
* the configuration information for the specified ADC peripheral.
* @retval None
*/
void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
{
u32 tmpreg = 0;
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_Mode(ADC_InitStruct->ADC_Mode));
assert_param(IS_ADC_TriggerSource(ADC_InitStruct->ADC_TriggerSource));
assert_param(IS_ADC_TimerTriggerSource(ADC_InitStruct->ADC_TimerTriggerSource));
assert_param(IS_ADC_Align(ADC_InitStruct->ADC_Align));
assert_param(IS_ADC_Channel(ADC_InitStruct->ADC_Channel));
assert_param(IS_ADC_BGVoltage(ADC_InitStruct->ADC_BGVoltage));
assert_param(IS_ADC_ReferencePositive(ADC_InitStruct->ADC_ReferencePositive));
tmpreg = ADCx->CR1;
tmpreg &= Init_CR1_MASK;
tmpreg|= ((ADC_InitStruct->ADC_Mode) |\
(ADC_InitStruct->ADC_TriggerSource)|\
(ADC_InitStruct->ADC_TimerTriggerSource)|\
(ADC_InitStruct->ADC_Align)|\
(ADC_InitStruct->ADC_Channel)|\
(ADC_InitStruct->ADC_BGVoltage)|\
(ADC_InitStruct->ADC_ReferencePositive));
ADCx->CR1 = tmpreg;
tmpreg = ADCx->CR2;
tmpreg &= Init_CR2_MASK;
tmpreg |= ((ADC_InitStruct->ADC_Prescaler)<<16);
ADCx->CR2 = tmpreg;
if(ADC_InitStruct->ADC_ReferencePositive== ADC_ReferencePositive_BG2v0)
{
/*启动 BG2V0如果使用这个基准,一定要开启BG2v0 */
ADCx->BGCR |=ADC_BGCR_BGE;
}
/*******************************/
/************************
**2。 在必经之路上,设置
*************************/
u32 AGENT_ID;
AGENT_ID=(*((u32 volatile*)(0x4001F02C)));
if(AGENT_ID !=0xFFFFFFFF)
{
AGENT_ID<<=3;
AGENT_H_stc_div1000=(s32)AGENT_ID>>19;
AGENT_H_stc_div1000<<=1;
AGENT_H_stc_div1000 /=1000;
AGENT_ID_stc_ENABLE =1;
}
else
{
AGENT_H_stc_div1000=0;
AGENT_ID_stc_ENABLE =0;
}
}
/***************************************************************/
void ADC_BG2V0_Enable(ADC_TypeDef* ADCx)
{
ADCx->BGCR |=ADC_BGCR_BGE;
}
/**
* @briefFills each ADC_InitStruct member with its default value.
* @note This function is used to initialize the global features of the ADC (
* Resolution, Data Alignment, continuous mode activation, External
* trigger source and edge, Sequence Scan Direction).
* @paramADC_InitStruct: pointer to an ADC_InitTypeDef structure which will
* be initialized.
* @retval None
*/
void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
{
ADC_InitStruct->ADC_Prescaler = 2; //ADC二分频,8/2=4 MHz
ADC_InitStruct->ADC_Mode = ADC_Mode_Single; //单次转换模式
ADC_InitStruct->ADC_TriggerSource = ADC_TriggerSource_Software;
ADC_InitStruct->ADC_TimerTriggerSource=ADC_TimerTriggerSource_TIM1ADC; //定时源触发选择TIM0事件
ADC_InitStruct->ADC_Align = ADC_Align_Right; //右对齐
ADC_InitStruct->ADC_Channel=ADC_Channel_0; //通道0,PC13
ADC_InitStruct->ADC_ReferencePositive= ADC_ReferencePositive_VDD; //选择VDDA作为正端参考电平
ADC_InitStruct->ADC_BGVoltage=ADC_BGVoltage_BG1v2;
}
/**
* @briefEnables or disables the specified ADC peripheral.
* @paramADCx: where x can be 1 to select the ADC1 peripheral.
* @paramNewState: new state of the ADCx peripheral.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Set the ADEN bit to Enable the ADC peripheral */
ADCx->CR1 |= ADC_CR1_EN;
}
else
{
/* Reset the ADEN to Disable the ADC peripheral */
ADCx->CR1 &= ~ADC_CR1_EN;
}
}
/**
* @briefConfigures for the selected ADC and its sampling time.
* @paramADCx: where x can be 1 to select the ADC peripheral.
* @paramADC_Channel: the ADC channel to configure.
* This parameter can be any combination of the following values:
* @ARG ADC_Channel_0: ADC Channel0 selected
* @arg ADC_Channel_1: ADC Channel1 selected
* @arg ADC_Channel_2: ADC Channel2 selected
* @arg ADC_Channel_3: ADC Channel3 selected
* @arg ADC_Channel_4: ADC Channel4 selected
* @arg ADC_Channel_5: ADC Channel5 selected
* @arg ADC_Channel_6: ADC Channel6 selected
* @arg ADC_Channel_7: ADC Channel7 selected
* @arg ADC_Channel_8: ADC Channel8 selected
* @arg ADC_Channel_9:
* @arg ADC_Channel_10:
* @arg ADC_Channel_11:
* @retval None
*/
void ADC_ChannelConfig(ADC_TypeDef* ADCx, u32 ADC_Channel)
{
u32 tmpreg=0;
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_Channel(ADC_Channel));
tmpreg = ADCx->CR1;
tmpreg &= ~ADC_CR1_CHS;
tmpreg |= ADC_Channel;
ADCx->CR1 = tmpreg;
}
void ADC_StartOfConversion(ADC_TypeDef* ADCx)
{
assert_param(IS_ADC_ALL_PERIPH(ADCx));
ADCx->CR1 |= ADC_CR1_SOC;
}
/*************************/
u16 ADC_DataCalculator1_6_0(ADC_TypeDef* ADCx, u16 data)
{
//s16 AGENT_H;
//u32 AGENT_ID;
s16 tmp;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
//AGENT_ID=(*((u32 volatile*)(0x4001F02C)));
if(0== AGENT_ID_stc_ENABLE )
{
if(((ADCx->CR1) &0x8000000) == 0x0)
{
if((ADCx->CR1&ADC_CR1_ALIGN)==ADC_CR1_ALIGN)
{
return data>>1;
}
else
{
return data<<1;
}
}
else
{
return data;
}
}
else
{
if(((ADCx->CR1) &0x8000000) == 0x8000000)
{
// AGENT_ID<<=3;
// AGENT_H=(s32)AGENT_ID>>19;
// AGENT_H<<=1;
if((data &0x2000)==0x2000)
{
// data=ADCx->DR;
data=data^0x3FFF;
data=data+1;
}
if((ADCx->CR1&ADC_CR1_ALIGN) == 0)
{
data <<= 2;
}
tmp = (s16)data;
tmp >>= 2;
tmp = tmp + AGENT_H_stc_div1000 ; /** 这个值已经算好了,直接使用 **/
tmp &=0xFFFE;
if(tmp > 8191)
{
tmp = 8191;
}
else if(tmp < -8191)
{
tmp = -8191;
}
if((ADCx->CR1&ADC_CR1_ALIGN)==ADC_CR1_ALIGN)
{
tmp <<= 2;
}
return (u16)tmp;
}
else
{
return data<<1;
}
}
}
/**
* @briefReturns the last ADCx conversion result data for ADC channel.
* @paramADCx: where x can be 1 to select the ADC1 peripheral.
* @retval The Data conversion value.
*/
/**
* @briefReturns the last ADCx conversion result data for ADC channel.
* @paramADCx: where x can be 1 to select the ADC1 peripheral.
* @retval The Data conversion value.
*/
u16 ADC_GetConversionValue(ADC_TypeDef* ADCx)
{
/* Check the parameters */
u16 data;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
/* Return the selected ADC conversion value */
data=ADCx->DR;
data=ADC_DataCalculator1_6_0(ADCx,data);
return data;
// int data;
// u16 AGENT_H,AGENT_L;
// u32 AGENT_ID;
// assert_param(IS_ADC_ALL_PERIPH(ADCx));
// /* Return the selected ADC conversion value */
// AGENT_ID=(*((u32 volatile*)(0x4001F02C)));
// if(( ((u32)(ADCx->CR1)) &0x8000000 ) == 0x8000000)
// {
// if((ADCx->DR&0x2000)==0x2000)
// {
// data=ADCx->DR;
// data=data^0x3FFF;
// data=data+1;
// }
// else
// {
// data=ADCx->DR;
// }
// /**************************************/
//// if(AGENT_ID<0xFFFFFFFF)
//// {
//// AGENT_H=AGENT_ID>>16;
//// AGENT_L=(u16)(AGENT_ID&0x0000FFFF);
//// data=(data)*AGENT_L/10000+AGENT_H/1000;
//// }
// data=data>>1;
// if(data>4095)
// {
// data=4095;
// }
// //data =ADC_DataCalculator(ADCx ,data );
// return data;
// }
// else
// {
// return ADCx->DR;
// }
}
void ADC_ITConfig(ADC_TypeDef* ADCx, u32 ADC_IT, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
assert_param(IS_ADC_IT(ADC_IT));
if (NewState != DISABLE)
{
/* Enable the selected ADC interrupts */
ADCx->CR1 |= ADC_IT;
}
else
{
/* Disable the selected ADC interrupts */
ADCx->CR1 &= (~ADC_IT);
}
}
/**
* @briefChecks whether the specified ADC flag is set or not.
* @paramADCx: where x can be 1 to select the ADC1 peripheral.
* @paramADC_FLAG: specifies the flag to check.
* This parameter can be one of the following values:
* @arg ADC_FLAG_EOC: End of conversion flag
* @arg ADC_FLAG_RDY: ADC Ready flag
* @retval The new state of ADC_FLAG (SET or RESET).
*/
FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, u32 ADC_FLAG)
{
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_FLAG(ADC_FLAG));
/* Check the status of the specified ADC flag */
if ((ADCx->SR & ADC_FLAG) != (u32)RESET)
{
/* ADC_FLAG is set */
bitstatus = SET;
}
else
{
/* ADC_FLAG is reset */
bitstatus = RESET;
}
/* Return the ADC_FLAG status */
returnbitstatus;
}
/**
* @brief ADC Average Command
* @param ADCx:ADC Peripheral
* @param NewState:FunctionalState type variable
* @retval None
*/
void ADC_AverageCmd(ADC_TypeDef* ADCx,FunctionalState NewState)
{
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if(NewState!=DISABLE)
{
ADCx->CR1 |= ADC_CR1_AVGE;
}
else
{
ADCx->CR1 &= (~ADC_CR1_AVGE);
}
}
/**
* @brief ADC Average Times Config
* @param ADCx:ADC Peripheral
* @param Times: the time of average conversion
* @arg ADC_AverageTimes_1: Average conversion 1 times
* @arg ADC_AverageTimes_2: Average conversion 2 times
* @arg ADC_AverageTimes_4: Average conversion 4 times
* @arg ADC_AverageTimes_8: Average conversion 8 times
* @arg ADC_AverageTimes_16: Average conversion 16 times
* @arg ADC_AverageTimes_32: Average conversion 32 times
* @arg ADC_AverageTimes_64: Average conversion 64 times
* @arg ADC_AverageTimes_128: Average conversion 128 times
* @retval None
*/
void ADC_AverageTimesConfig(ADC_TypeDef* ADCx,u32 Times)
{
u32 tmpreg=0;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_AverageTimes(Times));
tmpreg = ADCx->CR2;
tmpreg &= (~ADC_CR2_AVGT);
tmpreg |= ((Times));
ADCx->CR2 = tmpreg;
}
/**
* @brief ADC Ready Time Config
* @param ADCx:ADC Peripheral
* @param ReadyTime:0x0-0xFF
* @retval None
*/
void ADC_ReadyTimeConfig(ADC_TypeDef* ADCx,u32 ReadyTime)
{
u32 tmpreg=0;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
tmpreg = ADCx->CR2;
tmpreg &= (~ADC_CR2_RDTC);
tmpreg |= ReadyTime;
ADCx->CR2 = tmpreg;
}
/**
* @briefSet ADC sample times the specified ADC peripheral.
* @paramADCx: where x can be 1 to select the ADC1 peripheral.
* @paramsampletime: sample time value (3~255).
* @retval None
*/
void ADC_SampleTimeConfig(ADC_TypeDef* ADCx, u8 SampleTime)
{
u32 tmpreg = 0;
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_SampleTime(SampleTime));
tmpreg = ADCx->CR2;
tmpreg &= SetSampleTime_CR2_MASK;
tmpreg |= (SampleTime << 8);
ADCx->CR2 = tmpreg;
}
/**
* @brief ADC Scan Command
* @param ADCx:ADC Peripheral
* @param NewState:FunctionalState type variable
* @retval None
*/
void ADC_ScanCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Set the SCANE bit to Enable the ADC scan */
ADCx->CR1 |= ADC_CR1_SCANE;
}
else
{
ADCx->CR1 &= (~ADC_CR1_SCANE);
}
}
/**
* @brief ADC Scan Channel Config
* @param ADCx:ADC Peripheral
* @param ADC_Channel:ADC Peripheral
* @param ADC_Channel:the ADC channel to configure.
* This parameter can be one of the following values:
* @arg ADC_Channel_0: ADC Channel0 selected
* @arg ADC_Channel_1: ADC Channel1 selected
* @arg ADC_Channel_2: ADC Channel2 selected
* @arg ADC_Channel_3: ADC Channel3 selected
* @arg ADC_Channel_4: ADC Channel4 selected
* @arg ADC_Channel_5: ADC Channel5 selected
* @arg ADC_Channel_6: ADC Channel6 selected
* @arg ADC_Channel_7: ADC Channel7 selected
* @arg ADC_Channel_8: ADC Channel8 selected
* @arg ADC_Channel_9: ADC Channel9 selected
* @arg ADC_Channel_10: ADC Channel10 selected
* @arg ADC_Channel_11: ADC Channel11 selected
* @arg ADC_Channel_12: ADC Channel12 selected
* @arg ADC_Channel_13: ADC Channel13 selected
* @arg ADC_Channel_14: ADC Channel14 selected
* @arg ADC_Channel_15: ADC Channel15 selected
* @arg ADC_Channel_16: ADC Channel16 selected
* @arg ADC_Channel_17: ADC Channel17 selected
* @arg ADC_Channel_18: ADC Channel18 selected
* @param ScanChannel: ADC scan channel (0~19)
* @retval None
*/
void ADC_ScanChannelConfig(ADC_TypeDef* ADCx,u32 ADC_Channel,u32 ScanChannel)
{
u32 tmpreg=0;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_Channel(ADC_Channel));
assert_param(IS_ADC_ScanChannel(ScanChannel));
if(ScanChannel <= 5)
{
tmpreg = ADCx->SCHR1;
tmpreg &= (~(ADC_SCHR1_CH0<<(ScanChannel*5)));
tmpreg |= ((ADC_Channel>>16)<<ScanChannel*5);
ADCx->SCHR1 = tmpreg;
}
if((ScanChannel == 6)&&(ScanChannel == 7))
{
tmpreg = ADCx->SCHR2;
tmpreg &= (~(ADC_SCHR2_CH6<<((ScanChannel-6)*5)));
tmpreg |= ((ADC_Channel>>16)<<(ScanChannel-6)*5);
ADCx->SCHR2 = tmpreg;
}
}
/**
* @brief ADC Scan Channel Number Config
* @param ADCx:ADC Peripheral
* @param ScanNumber: the number of ADC scan channel (2~20)
* @retval None
*/
void ADC_ScanChannelNumberConfig(ADC_TypeDef* ADCx,u32 ScanNumber)
{
u32 tmpreg=0;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_ScanChannelNumber(ScanNumber));
tmpreg = ADCx->SCHR2;
tmpreg &= (~ADC_SCHR2_SCNT);
tmpreg |= ((ScanNumber-1) << 16);
ADCx->SCHR2 = tmpreg;
}
u16 ADC_GetScanData(ADC_TypeDef* ADCx,u32 ScanChannel)
{
/* Check the parameters */
u16 data;
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_ScanChannel(ScanChannel));
/* Return the selected ADC conversion value */
if (ScanChannel==0)
{
data = ADCx->SCHDR0;
}
else if(ScanChannel==1)
{
data = ADCx->SCHDR1;
}
else if(ScanChannel==2)
{
data = ADCx->SCHDR2;
}
else if(ScanChannel==3)
{
data = ADCx->SCHDR3;
}
else if(ScanChannel==4)
{
data = ADCx->SCHDR4;
}
else if(ScanChannel==5)
{
data = ADCx->SCHDR5;
}
else if(ScanChannel==6)
{
data = ADCx->SCHDR6;
}
else
{
data = ADCx->SCHDR7;
}
data=ADC_DataCalculator1_6_0(ADCx,data);
return data;
}
/**
* @}
*/
#技术资源#
PT32Y003数据手册
#技术资源#
用户参考手册:
#技术资源#
IDE环境配置指南2.0
#申请开发板#
PT32Y003x开发套件用户指南1.0(开发板使用说明)
需要开发板的请联系...
价格多少? @lonely 发表于 2024-3-26 09:53
价格多少?
TSSOP20不超过0.65 , 能不能寄开发板啊 xionghaoyun 发表于 2024-3-26 14:23
能不能寄开发板啊
可以的,VX18566239000 ,发地址来; ADC_DataCalculator()里面为啥要这样计算,不是12位的吗?怎么有8191 是12BIT ADC ghost_z 发表于 2024-4-6 14:12
ADC_DataCalculator()里面为啥要这样计算,不是12位的吗?怎么有8191
看他给的数据手册就知道了
12位就是最大4095呀,最后一位无效的就右移一位呀 ghost_z 发表于 2024-4-7 12:58
12位就是最大4095呀,最后一位无效的就右移一位呀
是的 PT32Y003 UART1 使用例程
/******************************************************************************
* @example UART
* @author应用开发团队
* @version V1.6.0
* @date 2023/12/18
* @brief 串口发送"欢迎使用PT32Y003x系列",使用其他设备向PT32Y003x MCU发送数据,MCU接收到的数据将通过串口打印出来
*
******************************************************************************
* @attention 串口特性为:波特率9600,1位停止位,无奇偶校验
* 注意:部分代码见PT32Y003x_it.c文件中UART0_Handler函数
*
* 当前的固件仅供指导, 目的是向客户提供有关其产品的编码信息,以节省他们的时间。
* 对于因此类固件的内容/或客户使用其中包含的编码信息而引起的任何索赔, * Pai-IC 不对任何直接, 间接或继发的损害负责。
*
* (C) 版权所有 Pai-IC Microelectronics
*
*****************************************************************************/
#include "PT32Y003x.h"
/**
* @brief 软件延时函数
* @param 无
* @retval 无
*/
void Software_Delay(void)
{
u8 i, j,x;
for(i=0; i<200; i++)
for(j=0; j<200; j++)
for(x=0; x<20; x++);
}
/**
* @brief 配置UART的复用引脚
* @param 无
* @retval 无
*/
void UART_GPIO_Config(void)
{
GPIO_DigitalRemapConfig(AFIOC, GPIO_Pin_7, AFIO_AF_0,DISABLE); //PD5 TX0PC7
GPIO_DigitalRemapConfig(AFIOD, GPIO_Pin_1, AFIO_AF_0,DISABLE); //PD6 RX0PD1
/* 配置UART管脚的复用功能 */
GPIO_DigitalRemapConfig(AFIOC, GPIO_Pin_7, AFIO_AF_3,ENABLE); //PD5 TX0PC7
GPIO_DigitalRemapConfig(AFIOD, GPIO_Pin_1, AFIO_AF_1,ENABLE); //PD6 RX0PD1
}
/**
* @brief 配置UART的工作模式
* @param 无
* @retval 无
*/
void UART_Mode_Config(void)
{
UART_InitTypeDefUART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct; //定义一个NVIC_InitTypeDef类型的结构体
/*NVIC配置*/
NVIC_InitStruct.NVIC_IRQChannel = UART1_IRQn; //设置中断向量号
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; //设置是否使能中断
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00; //设置中断优先级
NVIC_Init(&NVIC_InitStruct);
UART_ITConfig(UART1,UART_IT_RXNEI,ENABLE);
/*初始化UART0*/
UART_InitStruct.UART_BaudRate = 9600;
UART_InitStruct.UART_WordLengthAndParity = UART_WordLengthAndParity_8D;
UART_InitStruct.UART_StopBitLength = UART_StopBitLength_1;
UART_InitStruct.UART_ParityMode = UART_ParityMode_Even;
UART_InitStruct.UART_Receiver=UART_Receiver_Enable;
UART_InitStruct.UART_LoopbackMode=UART_LoopbackMode_Disable;
UART_Init(UART1, &UART_InitStruct);
/*开启UART0的收发功能*/
UART_Cmd(UART1, ENABLE);
}
/**
* @brief UART驱动函数
* @param 无
* @retval 无
*/
void UART_Driver(void)
{
UART_GPIO_Config();
UART_Mode_Config();
}
extern u16 data_rx;
extern u8 cnt;
int main (void)
{
u8 i=0;
UART_Driver();
printf("欢迎使用PT32Y003x系列\r\n");
while(1)
{
while(cnt)
{
UART_SendData(UART1,data_rx);
if(i==cnt)
{
i=0;
cnt=0;
}
}
}
}
#ifdefUSE_FULL_ASSERT
/**
* @briefReports the name of the source file and the source line number
* where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
*/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
printf("Wrong parameters value: file %s on line %ld\r\n", file, line);
/* Infinite loop */
while (1)
{
}
}
#endif
页:
[1]