主题中讨论的其他器件:CC2340R5
工具与软件:
您好!
为什么使用 GATT_WriteCharValue 发送10个字节的数据会导致错误 ISR?
这个代码将10字节数据从中央器件发送至外设。
void Write_doGattWriteCB(char *pdata) //uint8 index
{
bStatus_t status;
uint8_t charVals[100] = {0};
// uint8 index = *pdata;
// uint8_t charVals[4] = { 0x00, 0x02, 0x55, 0xFF };
req.handle = 43; // handle characteristic 3
req.pValue = GATT_bm_alloc(0, ATT_WRITE_REQ, strlen(pdata), NULL);//menuCurrentConnHandle
req.len = strlen(pdata);
// req.pValue[0] = (uint8*)pdata;
memcpy(req.pValue, pdata, req.len);
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue(0, &req, BLEAppUtil_getSelfEntity());
if ( status != SUCCESS )
{
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
UART2_write(uart, (const char *)"write fail...\r\n", strlen((const char *)"write fail...\r\n"), NULL);
}
else
UART2_write(uart, (const char *)"write ok...\r\n", strlen((const char *)"write ok...\r\n"), NULL);
}
* ======== callbackFxn ========
*/
void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
if (status != UART2_STATUS_SUCCESS)
{
/* RX error occured in UART2_read() */
while (1) {}
}
numBytesRead = count;
if(AT_State == 0)
sem_post(&sem);
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
char input;
const char echoPrompt[] = "Echoing characters:\r\n";
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;
/* Call driver init functions */
GPIO_init();
/* Configure the LED pin */
//GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Create semaphore */
semStatus = sem_init(&sem, 0, 0);
if (semStatus != 0)
{
/* Error creating semaphore */
while (1) {}
}
/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackFxn;
uartParams.baudRate = 115200;
uart = UART2_open(CONFIG_DISPLAY_UART, &uartParams);
if (uart == NULL)
{
/* UART2_open() failed */
while (1) {}
}
/* Turn on user LED to indicate successful initialization */
//GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Pass NULL for bytesWritten since it's not used in this example */
UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);
/* Loop forever echoing */
while (1)
{
switch(AT_State)
{
case 0:
numBytesRead = 0;
/* Pass NULL for bytesRead since it's not used in this example */
status = UART2_read(uart, &input, 1, NULL);
if (status != UART2_STATUS_SUCCESS)
{
/* UART2_read() failed */
while (1) {}
}
/* Do not write until read callback executes */
sem_wait(&sem);
if (numBytesRead > 0)
{
ch_buffer[ch_cnt++] = (uint8_t)input;
//AT command process flow.
if(strstr((const char *)ch_buffer,(const char *)"\r\n" ) != 0)
{
if(strcmp((const char *)ch_buffer,(const char *)"AT+CONNECT\r\n") == 0 )
{
AT_State = 3;
UART2_write(uart, (const char *)"\r\nMsg:success:", strlen((const char *)"\r\nMsg:success:"), NULL);
}
else
if(strcmp((const char *)ch_buffer,(const char *)"AT+WRITE\r\n") == 0 )
{
AT_State = 6;
UART2_write(uart, (const char *)"\r\nMsg:success:", strlen((const char *)"\r\nMsg:success:"), NULL);
}
status = UART2_write(uart, (const char *)ch_buffer, strlen((const char *)ch_buffer), NULL);
if (status != UART2_STATUS_SUCCESS)
{
/* UART2_write() failed */
while (1) {}
}
void *ptr = (void *)ch_buffer;
memset(ptr,0,100);
ch_cnt = 0;
}
}
break;
case 3: //connect device
UART2_write(uart, (const char *)"connect start...\r\n", strlen((const char *)"connect start...\r\n"), NULL);
sleep(1);
BLEAppUtil_invokeFunction(connect_dev, NULL);
sleep(1);
AT_State = 0;
break;
case 6: //send signal byte.
//BLEAppUtil_invokeFunction(Write_doGattWriteCB,&send_count);
BLEAppUtil_invokeFunction(Write_doGattWriteCB,(char*)"Test abc\r\n");
if(++send_count >= 4)
send_count = 0;
sleep(1);
AT_State = 0;
break;
}
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a fault
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
static void faultISR(void)
{
/* Enter an infinite loop. */
while (1) {}
}