Hi TI
Base on the demo projects SimpleBLECentral and SimpleBLEPeripheral.
Backgroud: http://e2e.ti.com/support/low_power_rf/f/538/p/318484/1108115.aspx#1108115
(CC2540)Only 20 Bytes data can be transmitted in a time! This is just the way BLE is setup.
SimpleBLECentral receive 40 bytes data from the uart. In order to transmit these 40 bytes data from SimpleBLECentral to SimpleBLEPeripheral, I have to break these 40 bytes into two packets(Accroding to Backgroud ) . The first packet contain the first 20 bytes data. The second packet contain the last 20 bytes data.
Then call the GATT_WriteCharValue twice.
The SimpleBLECentral program I had reedit is below:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void serialAppInitTransport( )
{
halUARTCfg_t uartConfig;
// configure UART
uartConfig.configured = TRUE;
uartConfig.baudRate = SBP_UART_BR;
uartConfig.flowControl = SBP_UART_FC;
uartConfig.flowControlThreshold = SBP_UART_FC_THRESHOLD;
uartConfig.rx.maxBufSize = SBP_UART_RX_BUF_SIZE;
uartConfig.tx.maxBufSize = SBP_UART_TX_BUF_SIZE;
uartConfig.idleTimeout = SBP_UART_IDLE_TIMEOUT;
uartConfig.intEnable = SBP_UART_INT_ENABLE;
uartConfig.callBackFunc = sbpSerialAppCallback;
// start UART
// Note: Assumes no issue opening UART port.
(void)HalUARTOpen( SBP_UART_PORT, &uartConfig );
return;
}
uint16 numBytes;
void sbpSerialAppCallback(uint8 port, uint8 event)
{
uint8 pktBuffer[SBP_UART_RX_BUF_SIZE];
// unused input parameter; PC-Lint error 715.
(void)event;
int i=0;
for(i=12000;i>0;i--)
{
asm("nop");
}
if ( (numBytes = Hal_UART_RxBufLen(port)) > 0 ) // In the example numBytes = 40
{
(void)HalUARTRead (port, pktBuffer, numBytes);
if (pktBuffer[0]=='A' && pktBuffer[1]=='T')
{
CommondHandle(pktBuffer, numBytes);
}
else
{
sbpGattWriteString(pktBuffer,numBytes/2); first -- tranmit the first 20 bytes data
for(i=12000;i>0;i--)
{
asm("nop");
}
sbpGattWriteString(pktBuffer+20,numBytes/2); second-- tranmit the last 20 bytes data
}
}
}
uint8 sbpGattWriteString(uint8 *pBuffer, uint16 length)
{
uint8 status;
uint8 len;
if(length > 20)
len = 20;
else
len = length;
attWriteReq_t req;
req.handle = simpleBLECharHdl;
req.len = len;
req.sig = 0;
req.cmd = 0;
osal_memcpy(req.value,pBuffer,len);
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
return status;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
I found that the SimpleBLEPeripheral only receive the first 20 bytes data, and the last 20 bytes data lost.
Is there some thing wrong with the app or the Osal ?
It seem that something wrong with the delay time between the first sbpGattWriteString and the second sbpGattWriteString .
It seem that there is a watch dog in the Osal, then I cannot extend the “nor” waiting time easily.
How can I solve this problem?
Thanks you !