I have a function which is searching for series of nine "1" in 64-bits variable(RFID tag number) and if found, moves them to the MSB. I have a huge problem with understanding why it does not work properly.
This is my variable
uint64_t volatile RFID_data2= 0b1111111110000000000000000000000000000000000000000000000000000000;
and i send it as pointer to function
test_flag= header_align(&RFID_data2);
uint8_t header_align(uint64_t *data){
uint64_t bit_mask=(uint64_t)
0b1111111110000000000000000000000000000000000000000000000000000000;
if((*data&bit_mask)==bit_mask){
PORTA ^= (1<<PORTA2);
return 1;
}
This condition is never fulfilled, but if i changed the conition to this :
if((*data==bit_mask){
PORTA ^= (1<<PORTA2);
return 1;
}
it appears to work good.
What is more i write another condition - which is working.
if((*data&bit_mask)>(bit_mask-1) && (*data&bit_mask)<(bit_mask+1 )){
PORTA ^= (1<<PORTA2);
return 1
As i can see it is a problem with AND '&' operation. In addition there are not any problems when i change RFID_data to 32 bits variable. I am working with Attiny441 and GCC compiler, Atmel Studio Is there any way to make it works on 64 bits?
I changed function to take uint64t (non-pointer) but the problem still persists. I also tried to create global varaible, and remove volatile modifer but it still does not working properly. Using a macro UINT64_C does not help also. It looks like :
uint64_t RFID_data;// global var
int main(void)
{
RFID_data=(0xFF80000000000000);// write into global var
uint64_t RFID_data2=(0xFF80000000000000);
while(1)
{
test_flag=header_align(RFID_data2);// send local variable
}
}
uint8_t header_align(uint64_t data){
uint64_t bit_mask = UINT64_C(0xFF80000000000000);
if((data&bit_mask)==bit_mask){
PORTA ^= (1<<PORTA2);//nothink
return 1;
}
I also tried to check if-condtion by global var:
if((RFID_data&bit_mask)==bit_mask){
PORTA ^= (1<<PORTA2);///nothink
return 1;
}
In both ways it does not returning 1, neither changing PORTA2 state.
It works only when i create a new local variable in header_allgin, like this:
uint8_t header_align(uint64_t data){
uint64_t RFID_data3 = UINT64_C(0xFF80000000000000);
uint64_t bit_mask = UINT64_C(0xFF80000000000000);
if((RFID_data3&bit_mask)==bit_mask){
PORTA ^= (1<<PORTA2);// here i can see signal
return 1;
}}
Is it way to make it work by global variable or byargument of function ?