【BG22-EK4108A 蓝牙开发套件】 一 、测试蓝牙信号强度+数据上下传
[复制链接]
本帖最后由 AnDawn 于 2022-1-21 22:12 编辑
今天测试的主角是ch5852m和BG22-EK4108A
首先测试ch582m
产品特点
- 32位RISC处理器WCH RISC-V4A
- 支持RV32IMAC指令集,支持硬件乘法和除法
- 32KB SRAM,1MB Flash,支持ICP、ISP和IAP,支持OTA无线升级
- 内置2.4GHz RF收发器和基带及链路控制,支持BLE5.3
- 支持2Mbps、1Mbps、500Kbps、125Kbps
- 接收灵敏度-98dBm,可编程+7dBm发送功率
- 提供协议栈和应用层API
- 内置温度传感器
- 内置RTC,支持定时和触发两种模式
- 提供2组USB2.0 全速Host/Device
- 提供14通道触摸按键
- 提供14通道12位ADC
- 提供4组UART,2组SPI,12路PWM,1路IIC
- 40个GPIO,其中4个支持5V信号输入
- 最低支持1.7V电源电压
- 内置AES-128加解密单元,芯片唯一ID
- 封装:QFN48
把ch582m设置为广播模式
以下代码
#include "CH58x_common.h"
#include "HAL.h"
tmosTaskID halTaskID;
/*******************************************************************************
* @fn Lib_Calibration_LSI
*
* @brief 内部32k校准
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void Lib_Calibration_LSI( void )
{
Calibration_LSI( Level_64 );
}
#if (defined (BLE_SNV)) && (BLE_SNV == TRUE)
/*******************************************************************************
* @fn Lib_Read_Flash
*
* @brief Lib 操作Flash回调
*
* input parameters
*
* @param addr.
* @param num.
* @param pBuf.
*
* output parameters
*
* @param None.
*
* @return None.
*/
u32 Lib_Read_Flash( u32 addr, u32 num, u32 *pBuf )
{
EEPROM_READ( addr, pBuf, num * 4 );
return 0;
}
/*******************************************************************************
* @fn Lib_Write_Flash
*
* @brief Lib 操作Flash回调
*
* input parameters
*
* @param addr.
* @param num.
* @param pBuf.
*
* output parameters
*
* @param None.
*
* @return None.
*/
u32 Lib_Write_Flash( u32 addr, u32 num, u32 *pBuf )
{
EEPROM_ERASE( addr, EEPROM_PAGE_SIZE*2 );
EEPROM_WRITE( addr, pBuf, num * 4 );
return 0;
}
#endif
/*******************************************************************************
* @fn CH57X_BLEInit
*
* @brief BLE 库初始化
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void CH57X_BLEInit( void )
{
uint8 i;
bleConfig_t cfg;
if ( tmos_memcmp( VER_LIB, VER_FILE, strlen( VER_FILE ) ) == FALSE )
{
PRINT( "head file error...\n" );
while( 1 )
;
}
SysTick_Config( SysTick_LOAD_RELOAD_Msk );
PFIC_DisableIRQ( SysTick_IRQn );
tmos_memset( &cfg, 0, sizeof(bleConfig_t) );
cfg.MEMAddr = ( u32 ) MEM_BUF;
cfg.MEMLen = ( u32 ) BLE_MEMHEAP_SIZE;
cfg.BufMaxLen = ( u32 ) BLE_BUFF_MAX_LEN;
cfg.BufNumber = ( u32 ) BLE_BUFF_NUM;
cfg.TxNumEvent = ( u32 ) BLE_TX_NUM_EVENT;
cfg.TxPower = ( u32 ) BLE_TX_POWER;
#if (defined (BLE_SNV)) && (BLE_SNV == TRUE)
FLASH_ROM_LOCK( 0 ); // 解锁flash
cfg.SNVAddr = ( u32 ) BLE_SNV_ADDR;
cfg.readFlashCB = Lib_Read_Flash;
cfg.writeFlashCB = Lib_Write_Flash;
#endif
#if( CLK_OSC32K )
cfg.SelRTCClock = ( u32 ) CLK_OSC32K;
#endif
cfg.ConnectNumber = ( PERIPHERAL_MAX_CONNECTION & 3 ) | ( CENTRAL_MAX_CONNECTION << 2 );
cfg.srandCB = SYS_GetSysTickCnt;
#if (defined TEM_SAMPLE) && (TEM_SAMPLE == TRUE)
cfg.tsCB = HAL_GetInterTempValue; // 根据温度变化校准RF和内部RC( 大于7摄氏度 )
#if( CLK_OSC32K )
cfg.rcCB = Lib_Calibration_LSI; // 内部32K时钟校准
#endif
#endif
#if (defined (HAL_SLEEP)) && (HAL_SLEEP == TRUE)
cfg.WakeUpTime = WAKE_UP_RTC_MAX_TIME;
cfg.sleepCB = CH58X_LowPower; // 启用睡眠
#endif
#if (defined (BLE_MAC)) && (BLE_MAC == TRUE)
for ( i = 0; i < 6; i++ )
cfg.MacAddr = MacAddr[5 - i];
#else
{
uint8 MacAddr[6];
GetMACAddress( MacAddr );
for(i=0;i<6;i++) cfg.MacAddr = MacAddr; // 使用芯片mac地址
}
#endif
if ( !cfg.MEMAddr || cfg.MEMLen < 4 * 1024 )
while( 1 )
;
i = BLE_LibInit( &cfg );
if ( i )
{
PRINT( "LIB init error code: %x ...\n", i );
while( 1 )
;
}
}
/*******************************************************************************
* @fn HAL_ProcessEvent
*
* @brief 硬件层事务处理
*
* input parameters
*
* @param task_id.
* @param events.
*
* output parameters
*
* @param events.
*
* @return None.
*/
tmosEvents HAL_ProcessEvent( tmosTaskID task_id, tmosEvents events )
{
uint8 * msgPtr;
if ( events & SYS_EVENT_MSG )
{ // 处理HAL层消息,调用tmos_msg_receive读取消息,处理完成后删除消息。
msgPtr = tmos_msg_receive( task_id );
if ( msgPtr )
{
/* De-allocate */
tmos_msg_deallocate( msgPtr );
}
return events ^ SYS_EVENT_MSG;
}
if ( events & LED_BLINK_EVENT )
{
#if (defined HAL_LED) && (HAL_LED == TRUE)
HalLedUpdate( );
#endif // HAL_LED
return events ^ LED_BLINK_EVENT;
}
if ( events & HAL_KEY_EVENT )
{
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
HAL_KeyPoll(); /* Check for keys */
tmos_start_task( halTaskID, HAL_KEY_EVENT, MS1_TO_SYSTEM_TIME(100) );
return events ^ HAL_KEY_EVENT;
#endif
}
if ( events & HAL_REG_INIT_EVENT )
{
#if (defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE) // 校准任务,单次校准耗时小于10ms
BLE_RegInit(); // 校准RF
#if( CLK_OSC32K )
Lib_Calibration_LSI(); // 校准内部RC
#endif
tmos_start_task( halTaskID, HAL_REG_INIT_EVENT, MS1_TO_SYSTEM_TIME( BLE_CALIBRATION_PERIOD ) );
return events ^ HAL_REG_INIT_EVENT;
#endif
}
if ( events & HAL_TEST_EVENT )
{
PRINT( "*\n" );
tmos_start_task( halTaskID, HAL_TEST_EVENT, MS1_TO_SYSTEM_TIME( 1000 ) );
return events ^ HAL_TEST_EVENT;
}
return 0;
}
/*******************************************************************************
* @fn HAL_Init
*
* @brief 硬件初始化
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
void HAL_Init()
{
halTaskID = TMOS_ProcessEventRegister( HAL_ProcessEvent );
HAL_TimeInit();
#if (defined HAL_SLEEP) && (HAL_SLEEP == TRUE)
HAL_SleepInit();
#endif
#if (defined HAL_LED) && (HAL_LED == TRUE)
HAL_LedInit( );
#endif
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
HAL_KeyInit( );
#endif
#if ( defined BLE_CALIBRATION_ENABLE ) && ( BLE_CALIBRATION_ENABLE == TRUE )
tmos_start_task( halTaskID, HAL_REG_INIT_EVENT, MS1_TO_SYSTEM_TIME( BLE_CALIBRATION_PERIOD ) ); // 添加校准任务,单次校准耗时小于10ms
#endif
// tmos_start_task( halTaskID, HAL_TEST_EVENT, 1600 ); // 添加一个测试任务
}
/*******************************************************************************
* @fn HAL_GetInterTempValue
*
* @brief 如果使用了ADC中断采样,需在此函数中暂时屏蔽中断.
*
* input parameters
*
* @param None.
*
* output parameters
*
* @param None.
*
* @return None.
*/
uint16 HAL_GetInterTempValue( void )
{
uint8 sensor, channel, config, tkey_cfg;
uint16 adc_data;
tkey_cfg = R8_TKEY_CFG;
sensor = R8_TEM_SENSOR;
channel = R8_ADC_CHANNEL;
config = R8_ADC_CFG;
ADC_InterTSSampInit();
R8_ADC_CONVERT |= RB_ADC_START;
while( R8_ADC_CONVERT & RB_ADC_START )
;
adc_data = R16_ADC_DATA;
R8_TEM_SENSOR = sensor;
R8_ADC_CHANNEL = channel;
R8_ADC_CFG = config;
R8_TKEY_CFG = tkey_cfg;
return ( adc_data );
}
测得最强信号强度30dB左右
由于空间有限15米左右测得结果93dB左右
测得结果比较满意
,下面测试BG22-EK4108A
BG22资源管理器工具包中包含了以下关键的硬件元素:
EFR32BG22无线壁虎SoC,76.8MHz工作频率,512kBkB闪存,32kBRAM
2.4GHz匹配网络和陶瓷天线
一个LED和一个按钮
车载SEGGERJ-Link调试器,便于编程和调试,其中包括一个USB虚拟COM端口和数据包跟踪接口(PTI)
MikroBUS插槽,用于连接点击板™和其他MikroBUS附加板
用于连接Qwiic连接系统硬件的Qwiic连接器
用于GPIO访问和连接到外部硬件的接线板
SubReset按钮
翻译成中文大概是这么个意思
套件的核心是EFR32BG22
/***************************************************************************//**
* @file
* @brief main() function.
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#include "sl_component_catalog.h"
#include "sl_system_init.h"
#include "app.h"
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#include "sl_power_manager.h"
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
#if defined(SL_CATALOG_KERNEL_PRESENT)
#include "sl_system_kernel.h"
#else // SL_CATALOG_KERNEL_PRESENT
#include "sl_system_process_action.h"
#endif // SL_CATALOG_KERNEL_PRESENT
int main(void)
{
// Initialize Silicon Labs device, system, service(s) and protocol stack(s).
// Note that if the kernel is present, processing task(s) will be created by
// this call.
sl_system_init();
// Initialize the application. For example, create periodic timer(s) or
// task(s) if the kernel is present.
app_init();
#if defined(SL_CATALOG_KERNEL_PRESENT)
// Start the kernel. Task(s) created in app_init() will start running.
sl_system_kernel_start();
#else // SL_CATALOG_KERNEL_PRESENT
while (1) {
// Do not remove this call: Silicon Labs components process action routine
// must be called from the super loop.
sl_system_process_action();
// Application process.
app_process_action();
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
// Let the CPU go to sleep if the system allows it.
sl_power_manager_sleep();
#endif
}
#endif // SL_CATALOG_KERNEL_PRESENT
}
不会排序,图是错的4312这个是顺序
某平台价格,
数据上下传下篇文章吧,582m做主机bg22做从机读取数据
|