#include "debug.h"
#include
#include
#define START? ? 0x57AB? ? ? ? ? ? /* 獲取芯片及固件版本 */
#define CMD01_GET_IC_VER? ? 0x01? ? ? ? ? ? /* 獲取芯片及固件版本 */
u16 RxBuffer2[100] = {0};
u8 TxBuffer2[] = "#Buffer2 Send from USART3 to USART2 using HalfDuplex Mode!"; /* Send by UART3 */
u16 TxBuffer1[] = {0x57,0xAB,0x01};
u8 TxCnt2 = 0;
u16 res;
void USART2_Init(void)
{
? ? GPIO_InitTypeDef? GPIO_InitStructure = {0};
? ? USART_InitTypeDef USART_InitStructure = {0};
? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
? ? /* USART2 TX-->A.2? ?RX-->A.3 */
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_Init(GPIOA, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
? ? GPIO_Init(GPIOA, &GPIO_InitStructure);
? ? USART_InitStructure.USART_BaudRate = 9600;
? ? USART_InitStructure.USART_WordLength = USART_WordLength_8b;
? ? USART_InitStructure.USART_StopBits = USART_StopBits_1;
? ? USART_InitStructure.USART_Parity = USART_Parity_No;
? ? USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
? ? USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
? ? USART_Init(USART2, &USART_InitStructure);
? ? USART_Cmd(USART2, ENABLE);
}
/*********************************************************************
?* @fn? ? ? main
?*
?* @brief? ?Main program.
?*
?* @return? none
?*/
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
SystemCoreClockUpdate();
Delay_Init();
USART_Printf_Init(115200);/* USART1 INIT DBUG */
USART2_Init(); /* USART2 INIT */
printf("SystemClk:%d\r\n",SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
printf("This is printf example\r\n");
for(int i=0;i<3;i++)
{
? ? Delay_Ms(10);
? ? USART_SendData(USART2, TxBuffer1[i]);
}
res=USART_ReceiveData(USART2);
printf("SystemClk:%d\r\n",res);
while(1)
? ? {
}
}