Corominas Marc

SPI newbie questions part II

Discussion created by Corominas Marc on Jun 8, 2010
Latest reply on Jun 11, 2010 by bigmac

Hi all,

 

we cam from: https://community.freescale.com/message/63224#63224

 

I understand that I have something worng in my code, I read a lot of documentation and look for some examples but I don't find a solution, my problem know is that I receive teh data from the sensor in reversebit mode (1=low and 0=high).

 

I configured the SPI modulo as:

  // SPI
  SPIC1_SPE=1;
  SPIC1_SPIE=0;//1
  SPIC1_MSTR=1;
  SPIC1_CPHA=0;
  SPIC1_SSOE=1;
  SPIC1_CPOL=1;
  SPIC1_LSBFE=0;
 
  //SPIC2
  SPIC2_MODFEN=0;
  SPIC2_BIDIROE=0;
 
 
  //SPIBR SPI clock = BUSCLK/4 = 1MHz
  SPIBR_SPPR2=1;
  SPIBR_SPR1=1;

 

then a GPIO as a SS, and make a loop as:

 


            STROBE=0;
            
            for (vegades=0;vegades<2;vegades++){   
                   
                   while (SPIS_SPTEF==0) clrWD();
                   
                   SPID=counter;   
                 
                   while (SPIS_SPRF==0) clrWD();
                   
                   res[vegades] = SPID;
              
                   counter=26;   //dummy
                                
                   
            }
            STROBE=1;

 

SO in that way I recevie 2 byte with the 10 bit angular position and 6 bits with the sensor status and all is ok.

 

But now I checking the sensor behavior: the data output  with the PWM sensor output and when the PWM output is like 26 I receive 998, I didn't realize of that the first time because I didn't need to compare both signals, and also I'm not able to localize the status bits (where are they and the logic levels don't match with the reality).

 

So i'm doing something wrong?

Outcomes