【BG22-EK4108A 蓝牙开发套件】 一 、信息互传失败+实现bg22ncp写入
<p>信息互传失败原因WCH</p><p>没有调通</p>
<p>通过官方例程还是无法读取不清楚为啥,</p>
<p>换了块板子还是不行具体情况以后再分析吧</p>
<p></p>
<p>/********************************** (C) COPYRIGHT *******************************<br />
* File Name : EXAM11.C<br />
* Author : WCH<br />
* Version : V1.0<br />
* Date : 2020/08/11<br />
* Description : CH573 C语言的U盘目录文件枚举程序<br />
支持: FAT12/FAT16/FAT32<br />
注意包含 CHRV3UFI.LIB/USBHOST.C/DEBUG.C<br />
*******************************************************************************/</p>
<p>/** 不使用U盘文件系统库,需要在工程属性预编译中修改 DISK_LIB_ENABLE=0 */<br />
/** U盘挂载USBhub下面,需要在工程属性预编译中修改 DISK_WITHOUT_USB_HUB=0 */</p>
<p>#include "CH58x_common.h"<br />
#include "CHRV3UFI.H"</p>
<p>__attribute__((aligned(4))) UINT8 RxBuffer; // IN, must even address<br />
__attribute__((aligned(4))) UINT8 TxBuffer; // OUT, must even address</p>
<p>/* 检查操作状态,如果错误则显示错误代码并停机 */<br />
void mStopIfError( UINT8 iError )<br />
{<br />
if ( iError == ERR_SUCCESS )<br />
{<br />
return; /* 操作成功 */<br />
}<br />
printf( "Error: %02X\n", ( UINT16 ) iError ); /* 显示错误 */<br />
/* 遇到错误后,应该分析错误码以及CHRV3DiskStatus状态,例如调用CHRV3DiskReady查询当前U盘是否连接,如果U盘已断开那么就重新等待U盘插上再操作,<br />
建议出错后的处理步骤:<br />
1、调用一次CHRV3DiskReady,成功则继续操作,例如Open,Read/Write等<br />
2、如果CHRV3DiskReady不成功,那么强行将从头开始操作(等待U盘连接,CHRV3DiskReady等) */<br />
while( 1 )<br />
{<br />
}<br />
}</p>
<p>int main()<br />
{<br />
UINT8 s, i;<br />
PUINT8 pCodeStr;<br />
UINT16 j;</p>
<p> SetSysClock( CLK_SOURCE_PLL_60MHz );</p>
<p> GPIOA_SetBits( GPIO_Pin_9 );<br />
GPIOA_ModeCfg( GPIO_Pin_8, GPIO_ModeIN_PU );<br />
GPIOA_ModeCfg( GPIO_Pin_9, GPIO_ModeOut_PP_5mA );<br />
UART1_DefInit();<br />
PRINT( "Start @ChipID=%02X \n", R8_CHIP_ID );</p>
<p> pHOST_RX_RAM_Addr = RxBuffer;<br />
pHOST_TX_RAM_Addr = TxBuffer;<br />
USB_HostInit();<br />
CHRV3LibInit(); //初始化U盘程序库以支持U盘文件</p>
<p> FoundNewDev = 0;<br />
printf( "Wait Device In\n" );<br />
while( 1 )<br />
{<br />
s = ERR_SUCCESS;<br />
if ( R8_USB_INT_FG & RB_UIF_DETECT ) // 如果有USB主机检测中断则处理<br />
{<br />
R8_USB_INT_FG = RB_UIF_DETECT; // 清连接中断标志<br />
s = AnalyzeRootHub(); // 分析ROOT-HUB状态<br />
if ( s == ERR_USB_CONNECT )<br />
FoundNewDev = 1;<br />
}<br />
<br />
if ( FoundNewDev || s == ERR_USB_CONNECT )<br />
{<br />
// 有新的USB设备插入<br />
FoundNewDev = 0;<br />
mDelaymS( 200 ); // 由于USB设备刚插入尚未稳定,故等待USB设备数百毫秒,消除插拔抖动<br />
s = InitRootDevice(); // 初始化USB设备<br />
if ( s == ERR_SUCCESS )<br />
{<br />
printf( "Start UDISK_demo @CHRV3UFI library\n" );<br />
// U盘操作流程:USB总线复位、U盘连接、获取设备描述符和设置USB地址、可选的获取配置描述符,之后到达此处,由CHRV3子程序库继续完成后续工作<br />
CHRV3DiskStatus = DISK_USB_ADDR;<br />
for ( i = 0; i != 10; i++ )<br />
{<br />
printf( "Wait DiskReady\n" );<br />
s = CHRV3DiskReady();<br />
if ( s == ERR_SUCCESS )<br />
{<br />
break;<br />
}<br />
mDelaymS( 50 );<br />
}<br />
if ( CHRV3DiskStatus >= DISK_MOUNTED ) //U盘准备好<br />
{<br />
/* 读文件 */<br />
printf( "Open\n" );<br />
strcpy( ( PCHAR ) mCmdParam.Open.mPathName, "/C51/CHRV3HFT.C" ); //设置要操作的文件名和路径<br />
s = CHRV3FileOpen(); //打开文件<br />
if ( s == ERR_MISS_DIR )<br />
{<br />
printf( "不存在该文件夹则列出根目录所有文件\n" );<br />
pCodeStr = ( PUINT8 ) "/*";<br />
}<br />
else<br />
{<br />
pCodeStr = ( PUINT8 ) "/C51/*"; //列出\C51子目录下的的文件<br />
}</p>
<p> printf( "List file %s\n", pCodeStr );<br />
for ( j = 0; j < 10000; j++ ) //限定10000个文件,实际上没有限制<br />
{<br />
strcpy( ( PCHAR ) mCmdParam.Open.mPathName, ( PCCHAR ) pCodeStr ); //搜索文件名,*为通配符,适用于所有文件或者子目录<br />
i = strlen( ( PCHAR ) mCmdParam.Open.mPathName );<br />
mCmdParam.Open.mPathName = 0xFF; //根据字符串长度将结束符替换为搜索的序号,从0到254,如果是0xFF即255则说明搜索序号在CHRV3vFileSize变量中<br />
CHRV3vFileSize = j; //指定搜索/枚举的序号<br />
i = CHRV3FileOpen(); //打开文件,如果文件名中含有通配符*,则为搜索文件而不打开<br />
/* CHRV3FileEnum 与 CHRV3FileOpen 的唯一区别是当后者返回ERR_FOUND_NAME时那么对应于前者返回ERR_SUCCESS */<br />
if ( i == ERR_MISS_FILE )<br />
{<br />
break; //再也搜索不到匹配的文件,已经没有匹配的文件名<br />
}<br />
if ( i == ERR_FOUND_NAME ) //搜索到与通配符相匹配的文件名,文件名及其完整路径在命令缓冲区中<br />
{<br />
printf( " match file %04d#: %s\n", ( unsigned int ) j, mCmdParam.Open.mPathName ); /* 显示序号和搜索到的匹配文件名或者子目录名 */<br />
continue; /* 继续搜索下一个匹配的文件名,下次搜索时序号会加1 */<br />
}<br />
else //出错<br />
{<br />
mStopIfError( i );<br />
break;<br />
}<br />
}<br />
i = CHRV3FileClose(); //关闭文件<br />
printf( "U盘演示完成\n" );<br />
}<br />
else<br />
{<br />
printf( "U盘没有准备好 ERR =%02X\n", ( UINT16 ) s );<br />
}<br />
}<br />
else<br />
{<br />
printf( "初始化U盘失败,请拔下U盘重试\n" );<br />
}<br />
}<br />
mDelaymS( 100 ); // 模拟单片机做其它事<br />
SetUsbSpeed( 1 ); // 默认为全速<br />
}<br />
}</p>
<p> </p>
<p> </p>
<p>实现bg22写入</p>
<p>/***************************************************************************//**<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</p>
<p>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();</p>
<p> // Initialize the application. For example, create periodic timer(s) or<br />
// task(s) if the kernel is present.<br />
app_init();</p>
<p>#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();</p>
<p> // Application process.<br />
app_process_action();</p>
<p>#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 />
}</p>
<p> </p>
<p> </p>
<p> </p>
<p>BG22ncp写入名称问题为啥名称后面老是加Example郁闷/?????</p>
<p></p>
<p>有知道为啥后面多名称的可以留言给我,谢谢啦!!!</p>
页:
[1]