cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with XOR on Bluepill (STM32F103)

SteenA
Associate

Hi Community

It shouldn't be so difficult, but I'm having problems with the XOR function on CubeIde and a STM32F103 (Bluepill Board)

I have this buffer:

#define NUM_CHANNELS 17

volatile uint16_t ihcData[NUM_CHANNELS];

 

I have these 2 functions that are working perfectly to clear a bit and to set a bit in this buffer:

 

uint8_t setOutput(uint8_t port, uint8_t channel)

{

       if ( (port < 1) || (port > 16) || (channel < 1) || (channel > 8)) return 3; // Indicate that values are out of range

       ihcData[channel -1] |= (1 << (port -1));

       return (ihcData[channel -1] & (1 << (port -1)) ) ? 1 : 0; // To indicate what the channel/port is set to

}

 

 

uint8_t clrOutput(uint8_t port, uint8_t channel)

{

      if ( (port < 1) || (port > 16) || (channel < 1) || (channel > 8)) return 3; // Indicate that values are out of range

      ihcData[channel -1] &= ~(1 << (port -1));

      return (ihcData[channel -1] & (1 << (port -1)) ) ? 1 : 0; // To indicate what the channel/port is set to

}

In the debugger the bit's are set and cleared correctly in the array as expected

 

And then I have this function that was supposed to toggle one bit in the buffer.

But whatever I tries it is not working !!

 

uint8_t toggleOutput(uint8_t port, uint8_t channel)

{

     if ( (port < 1) || (port > 16) || (channel < 1) || (channel > 8)) return 3; // Indicate that values are out of range

     ihcData[channel -1] ^= (1 << (port -1)); // Not working

      // ihcData[channel -1] = ihcData[channel -1] ^ (1 << (port -1)); // Not working

      // ihcData[4] ^= (1 << 4); // Not working

      // ihcData[4] = ihcData[4] ^ 0x00FF; // Not working

      return (ihcData[channel -1] & (1 << (port -1)) ) ? 1 : 0; // To indicate what the channel/port is set to

}

None of the attempts in the toggleOutput function are working, and I'm sure that I get into the function and the code is running since I can set the return value to a fixed value, or I can set or clear the bit value with one of the 2 working functions shown above, and the toggleOutput return function is given the correct return value (If bit is set to 1 or 0)

What am I don't wrong since the XOR function is not working ?

BTW. I'm using CubeIDE 1.14.0

 

Br

Steen

 

0 REPLIES 0