This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Issue in using ble_nus_string_send

Hi am using NRF52 board ...and am trying to send data(which is not a string) using ble_bus_string_send . I send data only once from a one second timer but the other side is receiving the data continuously ... many times in a second ? What I am doing wrong ..

Here is my timer init and ble_send_data functions ............

void timer_interrupt(int time_in_sec)
{
    NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; 
    NRF_TIMER1->TASKS_CLEAR = 1; 
    NRF_TIMER1->PRESCALER = 9;
    NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
    NRF_TIMER1->CC[0] = 31250;
    NRF_TIMER1->CC[1] = (31250*time_in_sec);
    NRF_TIMER1->INTENSET = ((TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos)
                         | (TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos)) ;
    NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
    NVIC_SetPriority(TIMER1_IRQn, APP_IRQ_PRIORITY_LOWEST);
    NVIC_EnableIRQ(TIMER1_IRQn);
    NRF_TIMER1->TASKS_START = 1;
}

void TIMER1_IRQHandler(void)
{  
		
    if ((NRF_TIMER1->EVENTS_COMPARE[0] != 0))
    {
        NRF_TIMER1->EVENTS_COMPARE[0] = 0;           //Clear compare register 0 event   
    }
		uint8_t data[10];
		static uint32_t timestamp=0;
		timestamp++;
		memcpy(data,&timestamp,sizeof(timestamp));
		uint8_t acc_data[] = {0x01,0x02,0x03,0x04,0x05,0x06};
		memcpy(data+4,acc_data,6);
		if(m_connected == true){
		ble_send_data(data,10,10);
			
		//	ble_send_data(data,6,11);
		}
}

void ble_send_data(uint8_t *data,uint8_t length,uint8_t msgtype)
{
	static uint8_t msg_buff[BLE_NUS_MAX_DATA_LEN];
	memset(msg_buff,'\0',BLE_NUS_MAX_DATA_LEN);
	msg_buff[HEADER_FIELD]= HEADER;
	msg_buff[SEQUENCE_NUMBER_FIELD] = sequence_number;
	msg_buff[TYPE_FIELD] = msgtype;
	msg_buff[PACKET_SIZE_FIELD]=length;
	msg_buff[NUM_PACKET_FIELD]=1;
	memcpy(&msg_buff[VALUABLE_INFO_FIELD],data,length);
	msg_buff[CRC_FIELD]=CRC8(data,length,7);
	ble_nus_string_send(&m_nus, msg_buff,BLE_NUS_MAX_DATA_LEN);
	sequence_number++;
}
Parents
  • In the timer IRQ routine I placed the code out of the if condition, when I placed it within if condition it worked properly.

    void TIMER1_IRQHandler(void) {

    if ((NRF_TIMER1->EVENTS_COMPARE[0] != 0))
    {
    
        NRF_TIMER1->EVENTS_COMPARE[0] = 0;           //Clear compare register 0 event  
        uint8_t data[10];
        static uint32_t timestamp=0;
        timestamp++;
        memcpy(data,&timestamp,sizeof(timestamp));
        uint8_t acc_data[] = {0x01,0x02,0x03,0x04,0x05,0x06};
        memcpy(data+4,acc_data,6);
        if(m_connected == true){
        ble_send_data(data,10,10);
    
        ble_send_data(data,6,11);
        } 
    }
    

    }

Reply
  • In the timer IRQ routine I placed the code out of the if condition, when I placed it within if condition it worked properly.

    void TIMER1_IRQHandler(void) {

    if ((NRF_TIMER1->EVENTS_COMPARE[0] != 0))
    {
    
        NRF_TIMER1->EVENTS_COMPARE[0] = 0;           //Clear compare register 0 event  
        uint8_t data[10];
        static uint32_t timestamp=0;
        timestamp++;
        memcpy(data,&timestamp,sizeof(timestamp));
        uint8_t acc_data[] = {0x01,0x02,0x03,0x04,0x05,0x06};
        memcpy(data+4,acc_data,6);
        if(m_connected == true){
        ble_send_data(data,10,10);
    
        ble_send_data(data,6,11);
        } 
    }
    

    }

Children
No Data
Related