Exemplo n.º 1
0
void WriteAcc(unsigned char reg, unsigned char value) {
	select_acc();
	SPI1_Write(XL362_REG_WRITE);
	SPI1_Write(reg);
	SPI1_Write(value);
	deselect_acc();
	return;
}
Exemplo n.º 2
0
unsigned char ReadAcc(unsigned char reg) {
	select_acc();
	SPI1_Write(XL362_REG_READ);
	SPI1_Write(reg);
	unsigned char read_val = SPI1_Read();
	deselect_acc();
	return read_val;
}
Exemplo n.º 3
0
void main(void)
{
     ADCON1=0x0F;              //all pins are digital IO
     
     //ss pin is output
     TRISB&=0xFB;
     ss=1;

     SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);   //initialize SPI in 00 mode
     
     //send data for D/A conversion
     ss=0;
     SPI1_Write(0x37);
     SPI1_Write(0xFF);
     ss=1;
     Delay_ms(1);

     //write code to read data from SPI bus if needed
     
     while(1);
}
Exemplo n.º 4
0
void ADXL362_Init(void){
	/*configure processor for the XL interrupt*/
	/*not currently being used, going off counters in main loop instead
	configure_pin_ss();
	configure_pin_irq();
	configure_irq_direction();
	configure_int_wakeup();
	configure_VIC_int();
	*/	
	configure_trigger_pin();

	configure_cs();	
	deselect_acc();
	rprintf("Pinsel1: %x\n\r", PINSEL1);

	/*configure accelerometer*/

	//enables the FIFO in stream mode, 384 sample deep watermark (128 in 3 axes)
	ConfigureAcc(XL362_FIFO_CTL, (XL362_FIFO_MODE_STREAM | XL362_FIFO_SAMPLES_AH));
	//set int1 to a watermark interrupt (watermark configured in FILTER_CONTROL; 128samples of each axis)
	ConfigureAcc(XL362_INTMAP1, XL362_INT_FIFO_WATERMARK);

	//set the sampling rate to 100Hz ****so the filter is set to 50Hz*****  Does not actually impact sampling rate
	//since it is externally triggered
	ConfigureAcc(XL362_FILTER_CTL, XL362_RATE_100);
	//set into low noise mode
	ConfigureAcc(XL362_POWER_CTL, XL362_LOW_NOISE2);
	//Configure activity interrups to >0 so if enabled, they don't trigger constantly (still not enabled, though)
	ConfigureAcc(XL362_THRESH_ACTH, 0x04);
	ConfigureAcc(XL362_TIME_ACT, 0xFF);
	//Configure external trigger sampling
	ConfigureAcc(XL362_FILTER_CTL, XL362_EXT_TRIGGER);

	//Do this last: enable the accelerometer into measurement mode
	ConfigureAcc(XL362_POWER_CTL, XL362_MEASURE_3D);

	//Clear out all the existing samples in the FIFO
	int samplesInFifo = readNumSamplesFifo();

	select_ADXL362();
	SPI1_Write(XL362_FIFO_READ);
	//2 bytes per sample
	for (int i = 0; i < 2*samplesInFifo; i++) {
		SPI1_Read();
		//rprintf("Accel: %x  %x\n\r", dataOutMSB, dataOutLSB);
		//rprintf("FIFO OUT: %d\n\r", dataOut);  //uncomment to see accel data as it comes from the FIFO
	}
	rprintf("%d samples in the FIFO\n\r", samplesInFifo);
	deselect_ADXL362();

}
static void mpu6000GyroInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    // PB13 - MPU_INT output on rev4 hardware
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStructure);


  /*  SPI1_Write(MPU_RA_PWR_MGMT_1, 0x80);      //PWR_MGMT_1    -- DEVICE_RESET 1
    delay(5);
    SPI1_Write( MPU_RA_SMPLRT_DIV, 0x00);      //SMPLRT_DIV    -- SMPLRT_DIV = 0  Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
    SPI1_Write( MPU_RA_PWR_MGMT_1, 0x03);      //PWR_MGMT_1    -- SLEEP 0; CYCLE 0; TEMP_DIS 0; CLKSEL 3 (PLL with Z Gyro reference)
    SPI1_Write( MPU_RA_INT_PIN_CFG, 0 << 7 | 0 << 6 | 0 << 5 | 0 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0);  // INT_PIN_CFG   -- INT_LEVEL_HIGH, INT_OPEN_DIS, LATCH_INT_DIS, INT_RD_CLEAR_DIS, FSYNC_INT_LEVEL_HIGH, FSYNC_INT_DIS, I2C_BYPASS_EN, CLOCK_DIS
    SPI1_Write( MPU_RA_CONFIG, MPU6000_DLPF_CFG);  //CONFIG        -- EXT_SYNC_SET 0 (disable input pin for data sync) ; default DLPF_CFG = 0 => ACC bandwidth = 260Hz  GYRO bandwidth = 256Hz)
    SPI1_Write( MPU_RA_GYRO_CONFIG, 0x18);      //GYRO_CONFIG   -- FS_SEL = 3: Full scale set to 2000 deg/sec
*/
	 SPI1_Write(MPUREG_PWR_MGMT_1, BIT_H_RESET);
    delay(100);
    SPI1_Write(MPUREG_PWR_MGMT_1, MPU_CLK_SEL_PLLGYROZ);      // Set PLL source to gyro output
   // SPI1_Write(MPUREG_USER_CTRL, 0b00110000);                 // I2C_MST_EN
    SPI1_Write(MPUREG_USER_CTRL, BIT_I2C_IF_DIS);             // Disable I2C bus
    SPI1_Write(MPUREG_SMPLRT_DIV, 0x04);                      // Sample rate = 200Hz    Fsample = 1Khz / (4 + 1) = 200Hz   
    SPI1_Write(MPUREG_CONFIG, 0); // BITS_DLPF_CFG_42HZ);            // Fs & DLPF Fs = 1kHz, DLPF = 42Hz (low pass filter)
    SPI1_Write(MPUREG_GYRO_CONFIG, BITS_FS_2000DPS);          // Gyro scale 2000?/s
    SPI1_Write(MPUREG_ACCEL_CONFIG, BITS_AFS_8G);             // Accel scale 4G
    SPI1_Write(MPUREG_INT_ENABLE, BIT_RAW_RDY_EN);            // INT: Raw data ready
    SPI1_Write(MPUREG_INT_PIN_CFG, BIT_INT_ANYRD_2CLEAR);     // INT: Clear on any read
    // ACC Init stuff. Moved into gyro init because the reset above would screw up accel config. Oops.
    // Accel scale 8g (4096 LSB/g)
		SPI1_Write( MPU_RA_CONFIG, mpuLowPassFilter);
    SPI1_Write( MPU_RA_ACCEL_CONFIG, 2 << 3);

}