一、环境说明:MSP430F5529+CC2564B双模蓝牙
协议栈版本CC256x MSP430 Bluetopia SDK\v1.5 R2,
修改SPPLEDemo_Lite工程,实现单片机向Android手机发送数据
二、问题描述:连续发送250k左右以内时速度比较快,传输速度大概能够达到每秒50kbyte左右,接下来速度突然变慢,每秒只有2k左右。
三、主要参数:
SPPConfigurationParams.MaximumFrameSize = 200;
SPPConfigurationParams.TransmitBufferSize = 987;
SPPConfigurationParams.ReceiveBufferSize = 348;
#define DEFAULT_INPUT_BUFFER_SIZE 1042
#define DEFAULT_OUTPUT_BUFFER_SIZE 384
四、相关源码:
static void BTPSAPI SPP_Event_Callback()
….
switch(SPP_Event_Data->Event_Data_Type)
{
…..
case etPort_Data_Indication:
if((TempLength = SPP_Data_Read(BluetoothStackID, SerialPortID, (Word_t)sizeof(Buffer), (Byte_t *)Buffer)) > 0)
{
if((Buffer[0]=='s')&&(Buffer[1]=='t')&&(Buffer[2]=='a')&&(Buffer[3]=='r')&&(Buffer[4]=='t'))
{
//收到手机"start"指令,就开始传输数据,数据量比较大估计20m左右
UPLOADING=TRUE;
BufferLength=0;
EPMUploadData('a');
}
}
case etPort_Transmit_Buffer_Empty_Indication:
if(UPLOADING==TRUE)
{
//如果数据还没有传完需要继续传输
EPMUploadData('b');
}
……
}
int EPMUploadData(int a) //向手机发送数据,计划传输102400*16字节
{
int i,Index,Index1,TempLength;
if(BufferLength>0) //检查buffer是否为空,不为空,说明为上一次发送剩余buffer,继续发送
{
for(i=0;i<BufferLength;i++)
{
Buffer[i]=0xff&a;
}
TempLength = SPP_Data_Write(BluetoothStackID, SerialPortID, (Word_t)BufferLength, (Byte_t *)Buffer);
if(TempLength>=0)
{
for(Index=0,Index1=TempLength;Index1<BufferLength;Index++,Index1++)
Buffer[Index] = Buffer[Index1];
BufferLength -= TempLength;
}
else
{
UPLOADING=FALSE;
}
}
while(UPLOADCOUNT<102400&&BufferLength==0)
{
for( i=0;i<16;i++)
Buffer[i]=0xff&a;
BufferLength=16;
UPLOADCOUNT++;
TempLength = SPP_Data_Write(BluetoothStackID, SerialPortID, (Word_t)BufferLength, (Byte_t *)Buffer);
if(TempLength>=0)
{
for(Index=0,Index1=TempLength;Index1<BufferLength;Index++,Index1++)
Buffer[Index] = Buffer[Index1];
BufferLength -= TempLength;
}
else
{
UPLOADING=FALSE;
}
}
if(UPLOADCOUNT==102400&&BufferLength==0) //完成计划发送量,发送'end'字符串给手机端
{
Buffer[0]='e';Buffer[1]='n';Buffer[2]='d';
BufferLength=3;
TempLength = SPP_Data_Write(BluetoothStackID, SerialPortID, (Word_t)BufferLength, (Byte_t *)Buffer);
UPLOADING=FALSE;
}
}
cedar_xuesong:
看下缓冲区的设置,估计是缓冲区用完了,后面的一直在等待发送
meigao cai:
回复 cedar_xuesong:
谢谢!能否详细一些?我上午重新调整了几个参数,发现更离谱的情况。
SPPConfigurationParams.MaximumFrameSize = (unsigned int)(329);
SPPConfigurationParams.TransmitBufferSize = (unsigned int)(987);SPPConfigurationParams.ReceiveBufferSize = (unsigned int)(348);
发送4组之后就不再发送了。通过DEBUG暂停之后,看程序跑到BSC (Bluetooth Stack Controller) API 一些函数里面在执行。
初步分析应该是发送数据一段时间之后进入了协议栈调度机制里面,调度之后没有回到我的程序代码。
请高手再帮忙分析分析!