Home > other >  CC2541, based on BLE4.0 protocol stack, the realization of DHT11 data serial printing, print format
CC2541, based on BLE4.0 protocol stack, the realization of DHT11 data serial printing, print format

Time:09-17

Protocol stack 1.3.0 version
Where
1. Add call DHT11 acquisition events (SimpleBLEPeripheral. C of SimpleBLEPeripheral_ProcessEvent SBP_START_DEVICE_EVT events)
 if (events & amp; SBP_START_DEVICE_EVT) 
{
//Start the Device
VOID GAPRole_StartDevice (& amp; SimpleBLEPeripheral_PeripheralCBs);

//Start Bond Manager
VOID GAPBondMgr_Register (& amp; SimpleBLEPeripheral_BondMgrCBs);

//Set the timer for the first periodic event
Osal_start_timerEx (simpleBLEPeripheral_TaskID SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);

//add
//start the timer event execution cycle collection DHT11 temperature and humidity
Osal_start_timerEx (simpleBLEPeripheral_TaskID SBP_DHT11_READ_HUMITURE_EVT, SBP_DHT11_READ_HUMITURE_EVT_PERIOD);
//add

Return (events ^ SBP_START_DEVICE_EVT);
}


2. Define DHT11 acquisition event, DHT11 a serial port to send events (SimpleBLEPeripheral. C) in the SimpleBLEPeripheral_ProcessEvent
Add
////cycle acquisition DHT11 temperature and humidity event 
If (events & amp; SBP_DHT11_READ_HUMITURE_EVT)
{
//off always interrupt, none will be 0 data
EA=0;

//acquisition DHT11 temperature and humidity
DHT11_Read_Humiture (sbDHT11_data);

//always interrupt
EA=1;

//start the timer event execute serial print DHT11 temperature and humidity
Osal_start_timerEx (simpleBLEPeripheral_TaskID SBP_DHT11_USART_EVT, SBP_DHT11_USART_EVT_PERIOD);

//start the timer event execution cycle collection DHT11 temperature and humidity
Osal_start_timerEx (simpleBLEPeripheral_TaskID SBP_DHT11_READ_HUMITURE_EVT, SBP_DHT11_READ_HUMITURE_EVT_PERIOD);

Return (events ^ SBP_DHT11_READ_HUMITURE_EVT);
}

//serial print DHT11 temperature and humidity event
If (events & amp; SBP_DHT11_USART_EVT)
{
Uint8 nString [15]={0};

//temperature
Sprintf (nString (char *), "DHT11 temp: % d, % d", sbDHT11_data [2], sbDHT11_data [3]).
NPI_PrintString (nString);
NPI_PrintString (" ");

//humidity
Sprintf (nString (char *), "DHT11 humi: % d, % d", sbDHT11_data [0], sbDHT11_data [1]).
NPI_PrintString (nString);
NPI_PrintString (" \ r \ n ");

Return (events ^ SBP_DHT11_USART_EVT);
}
//add


Results using serial debugging assistant, print data, found that the print format of a period of chaos, as shown, where is the problem? How to solve?
 
  • Related