Example #1
0
void acc_setup() {
  TRISAbits.TRISA4 = 0; // set CS to output and digital if necessary
  CS = 1;

  // select a pin for SDI1
  SDI1Rbits.SDI1R = 0b0001;//set RPB5 to be SDI1

  // select a pin for SD01
  RPB2Rbits.RPB2R = 0b0011; //set RPB2 to be SD01

  // Setup the master Master - SPI1
  // we manually control SS as a digital output 
  // since the pic is just starting, we know that spi is off. We rely on defaults here
 
  // setup spi1
  SPI1CON = 0;              // turn off the spi module and reset it
  SPI1BUF;                  // clear the rx buffer by reading from it
  SPI1BRG = 0x3;            // baud rate to 5MHz [SPI1BRG = (40000000/(2*desired))-1]
  SPI1STATbits.SPIROV = 0;  // clear the overflow bit
  SPI1CONbits.CKE = 1;      // data changes when clock goes from active to inactive
                            //    (high to low since CKP is 0)
  SPI1CONbits.MSTEN = 1;    // master operation
  SPI1CONbits.ON = 1;       // turn on spi
 
  // set the accelerometer data rate to 1600 Hz. Do not update until we read values
  acc_write_register(CTRL1, 0xAF); 

  // 50 Hz magnetometer, high resolution, temperature sensor on
  acc_write_register(CTRL5, 0xF0); 

  // enable continuous reading of the magnetometer
  acc_write_register(CTRL7, 0x0); 
  acc_write_register(0x21,0);
}
Example #2
0
void OnSetACCReg(u_char param_len, const char * parametres, u_char * rep_len, char * reponse)
{
    char param1,param2;
    sscanf(parametres,"%c,%c",&param1,&param2);
    if(acc_write_register(param1,param2))
    {
        *rep_len = sprintf(reponse,"%c",0);
    }
    else
    {
        *rep_len = sprintf(reponse,"%c",204);
    }
}
void acc_setup() {
  ANSELBbits.ANSB14 = 0; //Turn analog off on RB 14 for digital use with SCK1
  TRISBbits.TRISB4 = 0; // set CS to output and digital if necessary
  //SM: NO ANSELB.ANSB4 bit so I'm assuming B10 only has digital functionality
  CS = 1;

  // select a pin for SDI1
  SDI1Rbits.SDI1R = 0b0001;//Pin RB4 = Pin 11

  // select a pin for SD01
  RPA4Rbits.RPA4R = 0b0011; //Pin RA4 = Pin 12

  // Setup the master Master - SPI1
  // we manually control SS as a digital output
  // since the pic is just starting, we know that spi is off. We rely on defaults here

  // setup spi1
  SPI1CON = 0;              // turn off the spi module and reset it
  SPI1BUF;                  // clear the rx buffer by reading from it
  SPI1BRG = 0x3;            // baud rate to 5MHz [SPI1BRG = (40000000/(2*desired))-1]
  SPI1STATbits.SPIROV = 0;  // clear the overflow bit
  SPI1CONbits.CKE = 1;      // data changes when clock goes from active to inactive
                            //    (high to low since CKP is 0)
  SPI1CONbits.MSTEN = 1;    // master operation
  SPI1CONbits.ON = 1;       // turn on spi

  // set the accelerometer data rate to 1600 Hz. Do not update until we read values
  acc_write_register(CTRL1, 0xAF);

  // SM: set the accelerometer sensitivitiy to plus/minus 2g, anti-alias 50Hz
  acc_write_register(CTRL2,0x00);

  // 50 Hz magnetometer, high resolution, temperature sensor on
  acc_write_register(CTRL5, 0xF0);

  // enable continuous reading of the magnetometer
  acc_write_register(CTRL7, 0x0);
}
Example #4
0
int main() {

    BM_setup();

    display_clear();
    acc_write_register(0x00,0x04,(unsigned char *) buff,2);
    sprintf(message,"%d%d",buff[1],buff[2]);
    oledprint(1,10,message);
    display_draw();

//    while (1) {
//
//        display_clear();
//
//        acc_write_register(RDCVA, buff);
//
//        sprintf(buff,"Message: ",data);
//
//        oledprint(1,10,buff);
//        display_draw();
//    }
}