最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

stm32f407 hal uasrt1 使用

IT培训 admin 2浏览 0评论

stm32f407 hal uasrt 1 使用

    终于调试完成,伪hal的uart写法,用hal初始化uasrt,然后自己写中断里面的出来,合适少量数据的传输。不合适大量数据传输用。接下来有空学下大量数据传输写法吧。

 

 

 

C 源文件  

#include "main.h"
UART_HandleTypeDef huart1;
/********************************************BLE???????*********************************************************/
#define BLE_MAC_WE_ADD 24
#define BLE_SETTING_FLAG_ADD BLE_MAC_WE_ADD + 6 // 0x1F
#define BLE_TIME_CLC 8
#define BLE_GET_PRARTMENT_FROM_WE // ??WE?��????
#define BLE_SETTING_FLAG 0xaa/********************************************BLE SEN DATE REG And FLAG*********************************************************/volatile unsigned int gu16v_Uart_Rx_Time_Out_Cnt;
volatile unsigned int gu16v_Uart2_Tx_Time_Out_Cnt;
volatile unsigned int gu8v_Uart_BLE_SLEEP_DELAY;
#define UART_Length 32 // ?f?h???????L??
volatile unsigned char gu8v_UartTxBuf[UART_Length];
volatile unsigned char gu8v_UartRxBuf[UART_Length];
volatile unsigned char lu8v_TxBufoffset;
volatile unsigned char lu8v_TxBufLength;
volatile unsigned char lu8v_RxBufoffset;
volatile unsigned char lu8v_RxBufLength;
volatile unsigned char gu8v_UartTxing;
volatile unsigned char	gbv_UARTRxStart;
volatile unsigned char gbv_Data_Rx_Success;
/********************************************************************
Function: Uart?????????
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void MX_UART1_Init(void)
{huart1.Instance = USART1;huart1.Init.BaudRate = 9600;huart1.Init.WordLength = UART_WORDLENGTH_8B;huart1.Init.StopBits = UART_STOPBITS_1;huart1.Init.Parity = UART_PARITY_NONE;huart1.Init.Mode = UART_MODE_TX_RX;huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart1.Init.OverSampling = UART_OVERSAMPLING_16;if (HAL_UART_Init(&huart1) != HAL_OK){Error_Handler();}HAL_UART_Init(&huart1);lu8v_TxBufoffset =0;lu8v_TxBufLength =0;lu8v_RxBufLength =0xff;//__HAL_UART_ENABLE_IT(&huart1,UART_IT_TXE|UART_IT_RXNE);
//	HAL_UART_Transmit_IT(&huart1, &gu8v_UartTxBuf[lu8v_RxBufoffset], 1);lu8v_RxBufoffset = 0;//HAL_UART_Receive_IT(&huart1,&gu8v_UartRxBuf[lu8v_RxBufoffset], 1);__HAL_UNLOCK(&huart1);/* Enable the UART Parity Error Interrupt */__HAL_UART_ENABLE_IT(&huart1, UART_IT_PE);/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */__HAL_UART_ENABLE_IT(&huart1, UART_IT_ERR);/* Enable the UART Data Register not empty Interrupt */__HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
}
/********************************************************************
Function: Uart?????l???????��??????
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void USART1_IRQHandler(void) //串口1中断服务程序
{HAL_UART_IRQHandler(&huart1); //调用HAL库中断处理公用函数//-------------------------------------------------if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾){unsigned char *temp2;__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_RXNE); ////		 __HAL_UNLOCK(&huart1);/* Enable the UART Parity Error Interrupt *///  __HAL_UART_ENABLE_IT(&huart1, UART_IT_PE);/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */// __HAL_UART_ENABLE_IT(&huart1, UART_IT_ERR);/* Enable the UART Data Register not empty Interrupt */// __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);//  HAL_UART_RxCpltCallback(&huart1);gu8v_UartRxBuf[lu8v_RxBufoffset]=__HAL_UART_FLUSH_DRREGISTER(&huart1);if (gbv_UARTRxStart == 0){gbv_UARTRxStart = 1;gu16v_Uart_Rx_Time_Out_Cnt = 0;}if (lu8v_RxBufoffset == 1){lu8v_RxBufLength = gu8v_UartRxBuf[1] + 2;}lu8v_RxBufoffset++;lu8v_RxBufoffset = lu8v_RxBufoffset % UART_Length;if (lu8v_RxBufoffset > lu8v_RxBufLength){lu8v_RxBufLength = 0xff;lu8v_RxBufoffset = 0;gbv_Data_Rx_Success = 1;}}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_ORE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_NE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_NE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_FE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_FE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_PE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_PE); //lu8v_RxBufoffset = 0;}//-------------------------------------------------if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_TC); //if (lu8v_TxBufLength > UART_Length)				// 锟斤拷锟斤拷uart锟斤拷锟斤拷锟斤拷围,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷{lu8v_TxBufLength = UART_Length; //}if (lu8v_TxBufoffset < lu8v_TxBufLength){volatile  uint8_t*temp_1;temp_1=&gu8v_UartTxBuf[lu8v_TxBufoffset];HAL_UART_Transmit_IT(&huart1, temp_1, 1);//HAL_UART_Transmit_IT(&huart1, (u8*)gu8v_UartTxBuf[lu8v_TxBufoffset], 1);lu8v_TxBufoffset++;}else{gu8v_UartTxing = 0;}}
}
/********************************************************************
Function: UART TX ?_??l??
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_UartTxStart()
{//SET_BT_WAKEUP_MODE_OUT_LOW();delay_ms(6);gu8v_Uart_BLE_SLEEP_DELAY = 0;lu8v_TxBufoffset = 1;lu8v_TxBufLength = gu8v_UartTxBuf[1] + 3; // ????锟斤拷??锟斤拷gu8v_UartTxing = 1;HAL_UART_Transmit_IT(&huart1, (u8 *)gu8v_UartTxBuf, 1);}/********************************************************************
Function:   send buff ???
IO_IS_INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_Clear_lu8c_TX_FIFO(unsigned char data)
{unsigned char i;for (i = 0; i < UART_Length; i++){gu8v_UartTxBuf[i] = data;}
}
/********************************************************************
Function:   send buff ???
IO_IS_INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_Clear_gu8v_UartRxBuf(unsigned char data)
{unsigned char i;for (i = 0; i < UART_Length; i++){gu8v_UartRxBuf[i] = data;}
}
/********************************************************************
Function: ??????????????��????
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_USer_Send_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 6; offset < gu8v_UartTxBuf[6] + 5; offset++) //??{CheckSum ^= gu8v_UartTxBuf[offset];}return CheckSum;
}
/********************************************************************
Function: ??????????
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_BLE_Send_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 0; offset < gu8v_UartTxBuf[1] + 3; offset++) //??{CheckSum ^= gu8v_UartTxBuf[offset];}return CheckSum;
}
/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_BLE_Receive_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 0; offset < gu8v_UartRxBuf[1] + 2; offset++) //??{CheckSum ^= gu8v_UartRxBuf[offset];}return CheckSum;
}/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_User_Receive_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 6; offset < gu8v_UartRxBuf[6] + 5; offset++) //??{CheckSum ^= gu8v_UartRxBuf[offset];}return CheckSum;
}
/********************************************************************
Function: ??????????��??
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
void fun_fun_Modifying_Bluetooth_Rf_Power()
{fun_Clear_lu8c_TX_FIFO(0);gu8v_UartTxBuf[0] = BTSOPWRITE; //?????????gu8v_UartTxBuf[1] = 02;gu8v_UartTxBuf[2] = 0x28;gu8v_UartTxBuf[3] = BLE_RF_PWER_DB;gu8v_UartTxBuf[4] = fun_Get_BLE_Send_Data_CheckSum();fun_UartTxStart();
}
/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
void fun_BT_DATA_STATE_manage(void)
{#define TIMEBASE 2gu16v_Uart_Rx_Time_Out_Cnt =0;if (gu16v_Uart_Rx_Time_Out_Cnt > 250/TIMEBASE) //??????????// ??????????????{gu16v_Uart_Rx_Time_Out_Cnt = 0;gbv_UARTRxStart = 0;lu8v_RxBufoffset = 0;lu8v_RxBufLength = 0xff;fun_Clear_gu8v_UartRxBuf(0x00); //???????}gbv_Data_Rx_Success =0;if (gbv_Data_Rx_Success){volatile unsigned char temp, Rx_CheckSum = 0;gbv_Data_Rx_Success = 0;gbv_UARTRxStart = 0;lu8v_RxBufoffset = 0;			//fun_Clear_gu8v_UartRxBuf(0x00); //}if (gu16v_Uart2_Tx_Time_Out_Cnt > 200 / TIMEBASE){gu16v_Uart2_Tx_Time_Out_Cnt = 0;if (!gu8v_UartTxing){fun_fun_Modifying_Bluetooth_Rf_Power();}}
}

H 头文件 

//___________________________________________________________________
//___________________________________________________________________
//  Copyright : 2015 BY HOLTEK SEMICONDUCTOR INC
//  File Name : UART.c
// Description: UART�հl
//   Customer : Holtek Demo Code
//Targer Board: None
//     Note   :
//___________________________________________________________________
//___________________________________________________________________
#ifndef _USER_UART_H
#define _USER_UART_H
#define _BLE_IS_8232 
#define TIMEBASE1_CYCLE1S 800
/*****************************************************************************************************/
#define SET_BT_WAKEUP_MODE_OUT_HIGH()     {  PAout(5) = 1; }
#define SET_BT_WAKEUP_MODE_OUT_LOW()     {PAout(5) = 0;}
#define SET_BT_CONNETCT_IS_LOW()            PAin(4)==0 
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ���ú��� @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void MX_UART1_Init(void);
void fun_BT_DATA_STATE_manage(void);
void fun_Clear_Ble_Flag(void);
void fun_BLE_PWERON_Inint(void);
void fun_Get_MAC_From_WE(void);extern volatile unsigned char  lu8v_RxBufoffset;
extern volatile unsigned char  lu8v_RxBufLength;
extern volatile unsigned int gu16v_Uart_Rx_Time_Out_Cnt;
extern volatile unsigned int gu16v_Uart2_Tx_Time_Out_Cnt;
extern volatile unsigned int  gu8v_Uart_BLE_SLEEP_DELAY;
extern volatile unsigned long gu8v_BLE_Communication_Error_Count;
extern volatile unsigned char gu8v_BLE_IS_Error_State;/******************************************** ���� ����*********************************************************/
#define BLE_SYNCHRONIZATION_TOP              0xC5
#define BLE_SYNCHRONIZATION_RESPOND_TOP      0xC6  
#define BLE_ACTIVE_TRANSMISSION_TOP          0xC7 
#define BTSOPWRITE 0x22
enum {RF_POWER_11P8dBm    = 0,RF_POWER_9P6dBm        = 1,RF_POWER_7P9dBm        = 2,RF_POWER_6P3dBm        = 3,RF_POWER_4P9dBm        = 4,RF_POWER_3P3dBm        = 5,RF_POWER_1P6dBm        = 6,RF_POWER_0dBm        = 7,RF_POWER_m1P5dBm    = 8,RF_POWER_m3P1dBm    = 9,RF_POWER_m5dBm        = 10,RF_POWER_m7P3dBm    = 11,RF_POWER_m9P6dBm    = 12,RF_POWER_m11P5dBm    = 13,RF_POWER_m13P3dBm    = 14,RF_POWER_m16dBm        = 15,RF_POWER_m17P8dBm    = 16,RF_POWER_m19P5dBm    = 17,RF_POWER_OFF        = 18
};    
//BLE Power Setting
#define  BLE_RF_PWER_SET                   0x28
#define  BLE_RF_PWER_DB                    RF_POWER_0dBm
#define  BLE_RF_PWER_FAIL                  0x00
#define  BLE_RF_PWER_OK                    0x01#endif

 

stm32f407 hal uasrt 1 使用

    终于调试完成,伪hal的uart写法,用hal初始化uasrt,然后自己写中断里面的出来,合适少量数据的传输。不合适大量数据传输用。接下来有空学下大量数据传输写法吧。

 

 

 

C 源文件  

#include "main.h"
UART_HandleTypeDef huart1;
/********************************************BLE???????*********************************************************/
#define BLE_MAC_WE_ADD 24
#define BLE_SETTING_FLAG_ADD BLE_MAC_WE_ADD + 6 // 0x1F
#define BLE_TIME_CLC 8
#define BLE_GET_PRARTMENT_FROM_WE // ??WE?��????
#define BLE_SETTING_FLAG 0xaa/********************************************BLE SEN DATE REG And FLAG*********************************************************/volatile unsigned int gu16v_Uart_Rx_Time_Out_Cnt;
volatile unsigned int gu16v_Uart2_Tx_Time_Out_Cnt;
volatile unsigned int gu8v_Uart_BLE_SLEEP_DELAY;
#define UART_Length 32 // ?f?h???????L??
volatile unsigned char gu8v_UartTxBuf[UART_Length];
volatile unsigned char gu8v_UartRxBuf[UART_Length];
volatile unsigned char lu8v_TxBufoffset;
volatile unsigned char lu8v_TxBufLength;
volatile unsigned char lu8v_RxBufoffset;
volatile unsigned char lu8v_RxBufLength;
volatile unsigned char gu8v_UartTxing;
volatile unsigned char	gbv_UARTRxStart;
volatile unsigned char gbv_Data_Rx_Success;
/********************************************************************
Function: Uart?????????
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void MX_UART1_Init(void)
{huart1.Instance = USART1;huart1.Init.BaudRate = 9600;huart1.Init.WordLength = UART_WORDLENGTH_8B;huart1.Init.StopBits = UART_STOPBITS_1;huart1.Init.Parity = UART_PARITY_NONE;huart1.Init.Mode = UART_MODE_TX_RX;huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart1.Init.OverSampling = UART_OVERSAMPLING_16;if (HAL_UART_Init(&huart1) != HAL_OK){Error_Handler();}HAL_UART_Init(&huart1);lu8v_TxBufoffset =0;lu8v_TxBufLength =0;lu8v_RxBufLength =0xff;//__HAL_UART_ENABLE_IT(&huart1,UART_IT_TXE|UART_IT_RXNE);
//	HAL_UART_Transmit_IT(&huart1, &gu8v_UartTxBuf[lu8v_RxBufoffset], 1);lu8v_RxBufoffset = 0;//HAL_UART_Receive_IT(&huart1,&gu8v_UartRxBuf[lu8v_RxBufoffset], 1);__HAL_UNLOCK(&huart1);/* Enable the UART Parity Error Interrupt */__HAL_UART_ENABLE_IT(&huart1, UART_IT_PE);/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */__HAL_UART_ENABLE_IT(&huart1, UART_IT_ERR);/* Enable the UART Data Register not empty Interrupt */__HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
}
/********************************************************************
Function: Uart?????l???????��??????
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void USART1_IRQHandler(void) //串口1中断服务程序
{HAL_UART_IRQHandler(&huart1); //调用HAL库中断处理公用函数//-------------------------------------------------if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾){unsigned char *temp2;__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_RXNE); ////		 __HAL_UNLOCK(&huart1);/* Enable the UART Parity Error Interrupt *///  __HAL_UART_ENABLE_IT(&huart1, UART_IT_PE);/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */// __HAL_UART_ENABLE_IT(&huart1, UART_IT_ERR);/* Enable the UART Data Register not empty Interrupt */// __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);//  HAL_UART_RxCpltCallback(&huart1);gu8v_UartRxBuf[lu8v_RxBufoffset]=__HAL_UART_FLUSH_DRREGISTER(&huart1);if (gbv_UARTRxStart == 0){gbv_UARTRxStart = 1;gu16v_Uart_Rx_Time_Out_Cnt = 0;}if (lu8v_RxBufoffset == 1){lu8v_RxBufLength = gu8v_UartRxBuf[1] + 2;}lu8v_RxBufoffset++;lu8v_RxBufoffset = lu8v_RxBufoffset % UART_Length;if (lu8v_RxBufoffset > lu8v_RxBufLength){lu8v_RxBufLength = 0xff;lu8v_RxBufoffset = 0;gbv_Data_Rx_Success = 1;}}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_ORE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_NE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_NE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_FE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_FE); //lu8v_RxBufoffset = 0;}if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_PE) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_PE); //lu8v_RxBufoffset = 0;}//-------------------------------------------------if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC) == SET){__HAL_UART_CLEAR_FLAG(&huart1, UART_FLAG_TC); //if (lu8v_TxBufLength > UART_Length)				// 锟斤拷锟斤拷uart锟斤拷锟斤拷锟斤拷围,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷{lu8v_TxBufLength = UART_Length; //}if (lu8v_TxBufoffset < lu8v_TxBufLength){volatile  uint8_t*temp_1;temp_1=&gu8v_UartTxBuf[lu8v_TxBufoffset];HAL_UART_Transmit_IT(&huart1, temp_1, 1);//HAL_UART_Transmit_IT(&huart1, (u8*)gu8v_UartTxBuf[lu8v_TxBufoffset], 1);lu8v_TxBufoffset++;}else{gu8v_UartTxing = 0;}}
}
/********************************************************************
Function: UART TX ?_??l??
INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_UartTxStart()
{//SET_BT_WAKEUP_MODE_OUT_LOW();delay_ms(6);gu8v_Uart_BLE_SLEEP_DELAY = 0;lu8v_TxBufoffset = 1;lu8v_TxBufLength = gu8v_UartTxBuf[1] + 3; // ????锟斤拷??锟斤拷gu8v_UartTxing = 1;HAL_UART_Transmit_IT(&huart1, (u8 *)gu8v_UartTxBuf, 1);}/********************************************************************
Function:   send buff ???
IO_IS_INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_Clear_lu8c_TX_FIFO(unsigned char data)
{unsigned char i;for (i = 0; i < UART_Length; i++){gu8v_UartTxBuf[i] = data;}
}
/********************************************************************
Function:   send buff ???
IO_IS_INPUT	:
OUTPUT	:
NOTE	:
********************************************************************/
void fun_Clear_gu8v_UartRxBuf(unsigned char data)
{unsigned char i;for (i = 0; i < UART_Length; i++){gu8v_UartRxBuf[i] = data;}
}
/********************************************************************
Function: ??????????????��????
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_USer_Send_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 6; offset < gu8v_UartTxBuf[6] + 5; offset++) //??{CheckSum ^= gu8v_UartTxBuf[offset];}return CheckSum;
}
/********************************************************************
Function: ??????????
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_BLE_Send_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 0; offset < gu8v_UartTxBuf[1] + 3; offset++) //??{CheckSum ^= gu8v_UartTxBuf[offset];}return CheckSum;
}
/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_BLE_Receive_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 0; offset < gu8v_UartRxBuf[1] + 2; offset++) //??{CheckSum ^= gu8v_UartRxBuf[offset];}return CheckSum;
}/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
unsigned char fun_Get_User_Receive_Data_CheckSum()
{unsigned char offset, CheckSum = 0;for (offset = 6; offset < gu8v_UartRxBuf[6] + 5; offset++) //??{CheckSum ^= gu8v_UartRxBuf[offset];}return CheckSum;
}
/********************************************************************
Function: ??????????��??
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
void fun_fun_Modifying_Bluetooth_Rf_Power()
{fun_Clear_lu8c_TX_FIFO(0);gu8v_UartTxBuf[0] = BTSOPWRITE; //?????????gu8v_UartTxBuf[1] = 02;gu8v_UartTxBuf[2] = 0x28;gu8v_UartTxBuf[3] = BLE_RF_PWER_DB;gu8v_UartTxBuf[4] = fun_Get_BLE_Send_Data_CheckSum();fun_UartTxStart();
}
/********************************************************************
Function:
INPUT   :
OUTPUT  :
NOTE    :
********************************************************************/
void fun_BT_DATA_STATE_manage(void)
{#define TIMEBASE 2gu16v_Uart_Rx_Time_Out_Cnt =0;if (gu16v_Uart_Rx_Time_Out_Cnt > 250/TIMEBASE) //??????????// ??????????????{gu16v_Uart_Rx_Time_Out_Cnt = 0;gbv_UARTRxStart = 0;lu8v_RxBufoffset = 0;lu8v_RxBufLength = 0xff;fun_Clear_gu8v_UartRxBuf(0x00); //???????}gbv_Data_Rx_Success =0;if (gbv_Data_Rx_Success){volatile unsigned char temp, Rx_CheckSum = 0;gbv_Data_Rx_Success = 0;gbv_UARTRxStart = 0;lu8v_RxBufoffset = 0;			//fun_Clear_gu8v_UartRxBuf(0x00); //}if (gu16v_Uart2_Tx_Time_Out_Cnt > 200 / TIMEBASE){gu16v_Uart2_Tx_Time_Out_Cnt = 0;if (!gu8v_UartTxing){fun_fun_Modifying_Bluetooth_Rf_Power();}}
}

H 头文件 

//___________________________________________________________________
//___________________________________________________________________
//  Copyright : 2015 BY HOLTEK SEMICONDUCTOR INC
//  File Name : UART.c
// Description: UART�հl
//   Customer : Holtek Demo Code
//Targer Board: None
//     Note   :
//___________________________________________________________________
//___________________________________________________________________
#ifndef _USER_UART_H
#define _USER_UART_H
#define _BLE_IS_8232 
#define TIMEBASE1_CYCLE1S 800
/*****************************************************************************************************/
#define SET_BT_WAKEUP_MODE_OUT_HIGH()     {  PAout(5) = 1; }
#define SET_BT_WAKEUP_MODE_OUT_LOW()     {PAout(5) = 0;}
#define SET_BT_CONNETCT_IS_LOW()            PAin(4)==0 
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ���ú��� @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void MX_UART1_Init(void);
void fun_BT_DATA_STATE_manage(void);
void fun_Clear_Ble_Flag(void);
void fun_BLE_PWERON_Inint(void);
void fun_Get_MAC_From_WE(void);extern volatile unsigned char  lu8v_RxBufoffset;
extern volatile unsigned char  lu8v_RxBufLength;
extern volatile unsigned int gu16v_Uart_Rx_Time_Out_Cnt;
extern volatile unsigned int gu16v_Uart2_Tx_Time_Out_Cnt;
extern volatile unsigned int  gu8v_Uart_BLE_SLEEP_DELAY;
extern volatile unsigned long gu8v_BLE_Communication_Error_Count;
extern volatile unsigned char gu8v_BLE_IS_Error_State;/******************************************** ���� ����*********************************************************/
#define BLE_SYNCHRONIZATION_TOP              0xC5
#define BLE_SYNCHRONIZATION_RESPOND_TOP      0xC6  
#define BLE_ACTIVE_TRANSMISSION_TOP          0xC7 
#define BTSOPWRITE 0x22
enum {RF_POWER_11P8dBm    = 0,RF_POWER_9P6dBm        = 1,RF_POWER_7P9dBm        = 2,RF_POWER_6P3dBm        = 3,RF_POWER_4P9dBm        = 4,RF_POWER_3P3dBm        = 5,RF_POWER_1P6dBm        = 6,RF_POWER_0dBm        = 7,RF_POWER_m1P5dBm    = 8,RF_POWER_m3P1dBm    = 9,RF_POWER_m5dBm        = 10,RF_POWER_m7P3dBm    = 11,RF_POWER_m9P6dBm    = 12,RF_POWER_m11P5dBm    = 13,RF_POWER_m13P3dBm    = 14,RF_POWER_m16dBm        = 15,RF_POWER_m17P8dBm    = 16,RF_POWER_m19P5dBm    = 17,RF_POWER_OFF        = 18
};    
//BLE Power Setting
#define  BLE_RF_PWER_SET                   0x28
#define  BLE_RF_PWER_DB                    RF_POWER_0dBm
#define  BLE_RF_PWER_FAIL                  0x00
#define  BLE_RF_PWER_OK                    0x01#endif

 

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论