This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

missing data when using app_sched_event_put()

Hi there,

I am adding schedule to my application calling app_sched_event_put() inside a context interruption from Button to enable a sequential write to a memory using SPI after pressing a button when the softdevice have slot time available, but I am facing an issue with it, when the schedule event is fired I am losing previous data, and it is showing only the latest data ignoring the data used to feed the schedule

my code:

#define NRF_LOG_MODULE_NAME Peripheral
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
NRF_LOG_MODULE_REGISTER();

#include "peripheral.h"
#include "spi_transport.h"
#include "app_scheduler.h"

	uint8_t count;
	uint8_t buffer[300];
	uint16_t size = 30;

	static void timers_init(void)
	{
		// Initialize timer module, making it use the scheduler
		ret_code_t err_code = app_timer_init();
		APP_ERROR_CHECK(err_code);
	}

 	static void leds_init(void)
	{
		bsp_board_init(BSP_INIT_LEDS);
	}
	
	//----------------------------------
	struct QueueMessage
	{
		const uint8_t * buffer;
		uint8_t buffer_size;
	};
	
	static uint8_t _buffer[255];
	void Queue(const uint8_t * buffer, uint16_t buffer_size)
	{
		QueueMessage params;
		params.buffer_size = buffer_size;
		params.buffer = _buffer;
		memcpy(&_buffer, buffer, buffer_size);
		app_sched_event_put(&params, sizeof(params), QueueEvent);	
		
		NRF_LOG_INFO(" Queue data")
		NRF_LOG_HEXDUMP_INFO(buffer, buffer_size);
	}
	Static void QueueEvent(void * p_event_data, uint16_t event_data_size)
	{
		APP_ERROR_CHECK_BOOL((p_event_data != 0) && (event_data_size == sizeof(QueueMessage)));
		QueueMessage *params = (QueueMessage *)p_event_data;
		
		NRF_LOG_INFO(" Sent %d", params->buffer_size)
		NRF_LOG_HEXDUMP_INFO(params->buffer, params->buffer_size);
		
		NRF_LOG_INFO(" QueueEvent data")
		NRF_LOG_HEXDUMP_INFO(buffer, buffer_size);
		
		//SPI send...
	}

	static void button_event_handler(uint8_t pin_no, uint8_t button_action)
	{
		ret_code_t err_code;	
		if (button_action)
		{
			switch (pin_no)
			{
			case BUTTON1:
				bsp_board_led_on(LED1);
	
				for(int a = 0; a <3 ; a++)
				{
					count++;
					for (int j = 1; j < size; j++)
					{
						buffer[j] = count;
					}	
				Queue(buffer, size);
				memset(buffer, 0, size);	
				}			
				break;

			default:
				APP_ERROR_HANDLER(pin_no);
				break;
			}
		}
	}

	static void buttons_init(void)
	{
		ret_code_t err_code;
		static app_button_cfg_t buttons[] =
		{
			{ BUTTON1, false, BUTTON_PULL, button_event_handler }

		};

		err_code = app_button_init(buttons,ARRAY_SIZE(buttons),BUTTON_DETECTION_DELAY);
		APP_ERROR_CHECK(err_code);
			
		app_button_enable();
	}

	void initialize() //it is being called from my main.c
	{	
		timers_init();
		leds_init();
		buttons_init();
	}



output:

		Queue data:
		01 01 01 01 01 01 01 01 01 01 01
		01 01 01 01 01 01 01 01 01 01 01
		01 01 01 01 01 01 01 01 01 01 01
		
		Queue data:
		02 02 02 02 02 02 02 02 02 02 02 
		02 02 02 02 02 02 02 02 02 02 02 
		02 02 02 02 02 02 02 02 02 02 02 
		
		Queue data:	
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		
		QueueEvent data"
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		
		QueueEvent data"
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		
		QueueEvent data"
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 
		03 03 03 03 03 03 03 03 03 03 03 

details: SDK15.2, nRF52 DK

Parents Reply Children
No Data
Related