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