大家好
我在 cc2541器件的省电方面有一些问题。 使用预先设计的函数来配置 UART (HalUARTInit & HalUARTOpen RX & TX -> P0.2 & P0.3)它是有效的,但是使用 HalUARTWrite()器件不起作用,所以我必须按如下方式发送:
空 uart0Send (uint8* uartTxBuf、uint8 len)
{
uint8 uartTxBufLength = len;
uint16 uartTxIndex;
uint8数据;
//清除任何挂起的 TX 中断请求(设置 U0csr.TX_BYTE = 0)。
U0CSR &=~U0csr_TX_BYTE;
//循环:在 UART0 TX 线上发送每个 UART0样本。
对于(uartTxIndex = 0;uartTxIndex < uartTxBufLength;uartTxIndex++)
{
数据= uartTxBuf[uartTxIndex]+1;
U0DBUF =数据;
while (! (U0CSR 和 U0csr_TX_BYTE));
U0CSR &=~U0csr_TX_BYTE;
}
}
我认为这不起作用、因为堆肥设备 相当旧、我必须将其配置为9600波特、并且无法配置为115200波特、但我真的不知道这是原因。
预配置的选项如下:
INT_HEap_LEN=3072
HALNODEBUG
OSAL_CBTIMER_NUM_TESS=1
HAL_AES_DMA=true
HAL_LCD=false
HAL_LED=false
HAL_UART=true
HAL_UART_DMA=1
HAL_UART_ISR=0
HAL_DMA=true
power_saving_by OSCAR
注意:当我使用 power_saving 时、不存在字节转换。 因此、我实现了以下代码:
1。
#if 定义(power_saving_by OSCAR)
静态空 Bluewave_ChangeState (空)
{
bool Advertising_Enable;
uint8 new_state;
OSAL_STOP_timerEx (timerBluetooth_taskID、change_State_evt);
GAPRole_GetParameter (GAPROLE_State、new_state);
switch (new_state)
{
案例 GAPROLE_advertising:
{
advertising_Enable = false;
sleepModecount++;
if (sleepModeount == MAX_COUNT_ADV)
{
sleepModecount = 0;
GAPRole_SetParameter( GAPROLE_advertise_enabled,sizeof ( uint8 ),Advertising_Enable );
OSAL_START_timerEx (timerBluetooth_TaskID、change_State_evT、waiting_long_period);
halSleep (WAITING_LONG_PERIOD-1);
}
其他
{
GAPRole_SetParameter( GAPROLE_advertise_enabled,sizeof ( uint8 ),Advertising_Enable );
OSAL_START_timerEx (timerBluetooth_taskID、change_State_evT、waiting 时间段);
halSleep (WAITING_PERIOD-1);
}
}
中断;
案例 GAPROLE_等待:
{
advertising_Enable = true;
GAPRole_SetParameter( GAPROLE_advertise_enabled,sizeof ( uint8 ),Advertising_Enable );
OSAL_START_timerEx (timerBluetooth_TaskID、change_State_evt、advertising_period);
}
中断;
}
}
#endif
因此、该器件会唤醒200ms、然后睡眠800ms、然后当已经有五个广播状态时、会进入睡眠状态3秒、然后再次启动200ms 800ms 和3秒。 这是因为当器件处于睡眠模式时、电流消耗以 uA 为单位、低于10uA。
在调试模式下、一切工作正常、但当电池电量耗尽时、器件停止工作。 使用一个断点、我发现问题是等待缓冲区的" while "是不忙碌的、因为注释这句话时器件继续工作、但数据丢失。 当"while"处于活动状态时、手机无法与设备连接。
请有人帮助我吗?