SAM R21 Xplained Pro - My boolean variable has an int value

Moderator: nferre

ricardogomes
Posts: 13
Joined: Thu Jan 22, 2015 7:36 pm

SAM R21 Xplained Pro - My boolean variable has an int value

Thu Jul 23, 2015 7:41 pm

I'm experiencing a weird bug. In some interrupt, I put a boolean variable with a true value and I start a timer. In my main, I read from a SPI SERCOM if that variable is true. When the timer expires, the callback function puts the variable false.
Because it was not working as I wanted, I put a breakpoint in the expression where I put the variable false.

I looked to the Watchlist and I saw that my variable had an int value (sometimes 132, other 140, other 160...). I have already tried to declare the variable as bool, static bool or volatile bool but it's always with an integer value instead of true or false :\

Does anyone know how to resolve this bug?

Code: Select all

static void extint_detection_callback(void)
{
	canreadacceleration = true;
	start_tc_acceleration();
}
 

Code: Select all

static void tc_callback_to_send_acceleration(struct tc_module *const module_inst)
{
 	canreadacceleration = false;
}
ricardogomes
Posts: 13
Joined: Thu Jan 22, 2015 7:36 pm

Re: SAM R21 Xplained Pro - My boolean variable has an int va

Fri Jul 24, 2015 11:33 am

Yes, I know. But why does my boolean variable gets a value different than true or false? I don't give that instruction. How can I avoid that from happening?
ricardogomes
Posts: 13
Joined: Thu Jan 22, 2015 7:36 pm

Re: SAM R21 Xplained Pro - My boolean variable has an int va

Mon Jul 27, 2015 12:57 pm

While debugging my code, I've realized why my variable is not true sometimes and I want to know if you have a solution for my problem. When the interrupt happens, I put a boolean variable in true state and that "allows" my program to enter in a cycle: "read spi, can_send_wireless = true" and a timer starts.
When the timer expires, the callback function puts the variable in false state so my program can't enter in the cycle mentioned before.
The problem is that if when the timer callback function puts the variable false and my program is inside the read_spi function, the variable goes to false and the goes to true again.

How can I avoid this? Any idea?

MAIN:

Code: Select all

while (true)
	{	
		if (canreadacceleration)
		{
			if(!appDataReqBusy){
accel = read_spi();
			}
		}
		SYS_TaskHandler();
		APP_TaskHandler();
	}

Code: Select all

volatile uint8_t *read_spi()
{
	uint8_t getDataXYZBuffer[XYZDATA_BUF_LENGTH] = {0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  /* */
	uint8_t DataXYZBuffer[XYZDATA_BUF_LENGTH]; // DataXYZBuffer[0] = dummy. DataXYZBuffer[1] = x0 .... DataXYZBuffer[7] = z1
	
	spi_select_slave(&spi_master_instance, &spi_slave_ADXL375, true);
	spi_transceive_buffer_wait(&spi_master_instance,getDataXYZBuffer,DataXYZBuffer,XYZDATA_BUF_LENGTH);
	spi_select_slave(&spi_master_instance, &spi_slave_ADXL375, false);
	return DataXYZBuffer;
}

Return to “SAM9-based”

Who is online

Users browsing this forum: No registered users and 3 guests