Beispiel #1
0
//Connect Microphone to PGA
void Connect_Microphone_Input(void)
{
	I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x34, 0x0C);  //IN3L routed to Left MICPGA
	Delay(Codec_Pause);
}
Beispiel #2
0
//Microphone Power Handling
void Turn_On_Bias(void)
{
	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x33, 0x40);
	Delay(Codec_Pause);
}
Beispiel #3
0
//Connect IQ Inputs to PGA
void Connect_IQ_Inputs(void)
{
	I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x34, 0x30);  //IN2L routed to Left MICPGA
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x37, 0x30);  //IN2R routed to Right MICPGA
	Delay(Codec_Pause);
}
Beispiel #4
0
void Calibrate (void)
{
	unsigned char reg_val = 0;

	while (!reg_val)		// Wait for a first set of data
	{
		reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, STATUS_REG) & 0x08;
	}

	I2C_ReadMultiRegisters(MMA845x_I2C_ADDRESS, OUT_X_MSB_REG, 6, AccData);		// Read data output registers 0x01-0x06

	Xout_14_bit = ((short) (AccData[0]<<8 | AccData[1])) >> 2;		// Compute 14-bit X-axis output value
	Yout_14_bit = ((short) (AccData[2]<<8 | AccData[3])) >> 2;		// Compute 14-bit Y-axis output value
	Zout_14_bit = ((short) (AccData[4]<<8 | AccData[5])) >> 2;		// Compute 14-bit Z-axis output value

	Xoffset = Xout_14_bit / 8 * (-1);		// Compute X-axis offset correction value
	Yoffset = Yout_14_bit / 8 * (-1);		// Compute Y-axis offset correction value
	Zoffset = (Zout_14_bit - SENSITIVITY_2G) / 8 * (-1);		// Compute Z-axis offset correction value

	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x00);		// Standby mode to allow writing to the offset registers
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_X_REG, Xoffset);
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Y_REG, Yoffset);
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, OFF_Z_REG, Zoffset);
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG3, 0x00);		// Push-pull, active low interrupt
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG4, 0x01);		// Enable DRDY interrupt
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG5, 0x01);		// DRDY interrupt routed to INT1 - PTA14
	//I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x3D);		// ODR = 1.56Hz, Reduced noise, Active mode
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0xC3);		// ODR = 1.56Hz, Reduced noise, Active mode
}
Beispiel #5
0
void Set_LO_Gain(int LO_gain)
{
	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x12, LO_gain);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x13, LO_gain);
	Delay(Codec_Pause);
}   // End of Set_LO_Gain
Beispiel #6
0
void Accelerometer_Init (void)
{
	unsigned char reg_val = 0;

	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x40);		// Reset all registers to POR values

	do		// Wait for the RST bit to clear
	{
		reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, CTRL_REG2) & 0x40;
	} 	while (reg_val);

	I2C_WriteRegister(MMA845x_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x00);		// +/-2g range -> 1g = 16384/4 = 4096 counts
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x00);		// 0x02High Resolution mode
	I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0xC3);// 0x3D);	// ODR = 1.56Hz, Reduced noise, Active mode
}
Beispiel #7
0
//Disconnect Everything from PGA input
void Disconnect_PGA(void)
{
	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x34, 0x00);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x37, 0x00);
	Delay(Codec_Pause);

}
Beispiel #8
0
void SS_SetColon(uint8_t addr, uint8_t data) {
// 0=off, 1=on
// the colon is represented by bit1 at address 0x04. There are three other single LED
// "decimal points" on the display, which are at the following bit positions
// bit2=top left, bit3=bottom left, bit4=top right

    I2C_WriteRegister(addr,0x04,data<<1);
}
Beispiel #9
0
void Set_HP_Gain(int HP_gain)
{

	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01) != 0) {
		return;
	}
	Delay(Codec_Pause);

	if (HP_gain < 0) HP_gain += 64;

	I2C_WriteRegister(CODEC_ADDRESS, 0x10, HP_gain);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x11, HP_gain);
	Delay(Codec_Pause);
}   // End of Set_HP_Gain
Beispiel #10
0
void SS_SetDigitRaw(uint8_t addr, uint8_t digit, uint8_t data) {
// digits (L-to-R) are 0,1,2,3
// Send segment-data to specified digit (0-3) on LED display
  if (digit>4) return;                        // only digits 0-4
  if (digit>1) digit++;                       // skip over colon @ position 2
  digit <<= 1;                                // multiply by 2
  I2C_WriteRegister(addr, digit, data);      // send segment-data to display
}
Beispiel #11
0
void FM_UpdateRegisters(){
	int index = 0;
	for(int i=0; i++; i<16){
		index = i;
		if(i>5){
			index = i+5;
		}
		I2C_WriteRegister(SI4703, index, registers[i]);
	}
}
Beispiel #12
0
void Set_PGA_Gain(int PGA_gain)
{

	if (PGA_gain < PGA_GAIN_MIN)
		PGA_gain = PGA_GAIN_MIN;
	if (PGA_gain > PGA_GAIN_MAX)
		PGA_gain = PGA_GAIN_MAX;

	// Check for failure accessing I2C.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x01) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x3B, PGA_gain);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x3C, PGA_gain);
	Delay(Codec_Pause);
}   // End of Set_PGA_gain
Beispiel #13
0
void Set_ADC_DVC(int ADC_gain)
{

	if (ADC_gain > ADC_GAIN_MAX)
		ADC_gain = ADC_GAIN_MAX;
	if (ADC_gain < ADC_GAIN_MIN)
		ADC_gain = ADC_GAIN_MIN;
	if (ADC_gain < 0) ADC_gain += 127;

	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x00) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x53, ADC_gain);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x54, ADC_gain);
	Delay(Codec_Pause);
}   // End of Set_ADC_DVC
Beispiel #14
0
void Set_DAC_DVC(int DAC_gain)
{

	if (DAC_gain > DAC_GAIN_MAX)
		DAC_gain = DAC_GAIN_MAX;
	if (DAC_gain < DAC_GAIN_MIN)
		DAC_gain = DAC_GAIN_MIN;
	if (DAC_gain < 0)
		DAC_gain += 256;

	// Check for error writing.
	if (I2C_WriteRegister(CODEC_ADDRESS, 0x00, 0x00) != 0) {
		return;
	}
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x41, DAC_gain);
	Delay(Codec_Pause);

	I2C_WriteRegister(CODEC_ADDRESS, 0x42, DAC_gain);
	Delay(Codec_Pause);
}   // End of Set_Dig_DVC
void IMU_magnet_init(void) {
    I2C_WriteRegister(HMC_ADDRESS, HMC_CONFIG_A, 0x70); //8 average, 15Hz, normal measurement
    I2C_WriteRegister(HMC_ADDRESS, HMC_CONFIG_B, 0x20); //configuration gain = 1.3
    I2C_WriteRegister(HMC_ADDRESS, HMC_MODE, 0x00); //continuous measurement mode
    TC_DelayMs(10);
}
Beispiel #16
0
/******************************************************************************
* Function name : main
* Description 	: Main testing loop
* Input param 	: None
* Return 		    : None
* See also 		  : None
*******************************************************************************/
void main (void) { 
  /* peripheral initialization */  
	#ifdef FAST_I2C_MODE
  CLK->CKDIVR = 0x00;             // sys clock / 1
	#else
  CLK->CKDIVR = 0x01;             // sys clock / 2
	#endif
  
	// Set GPIO for LED uses 
  GPIOH->DDR |=  0x0F;            
  GPIOH->CR1 |=  0x0F;            
  
	// initialize timer 4 mandatory for timout and tick measurement 
  TIM4_Init();                    
  
	// Initialize I2C for communication
	I2C_Init();                     
  
  // initialization of dummy field for test purpose    
  memcpy(Dummy, DUMMY_INIT, MAX_DUMMY);
  
	#ifndef _COSMIC_
  err_save= 0;
  TIM4_tout= loop_count= 0;
	#endif
  
	// Enable all interrupts  
	enableInterrupts();

  /* main test loop */
  while(1) {
		// switch on LED1 at the beginning of test
    switch_on(LED1);
		// write 1 data bytes with offset 8 from Dummy filed to slave memory
    set_tout_ms(10);
    I2C_WriteRegister(8, 1, &Dummy[8]);
    // read 1 byte with offset 8 back from the image at slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_ReadRegister(8, 1, &Dummy[8]);
    }
    // write 6 bytes with offset 2 from Dummy filed to slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_WriteRegister(2, 6, &Dummy[2]);
    }
    // read 6 bytes with offset 2 back from the image at slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_ReadRegister(2, 6, &Dummy[2]);
    }
    // write 1 byte with offset 9 from Dummy filed to slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_WriteRegister(9, 1, &Dummy[9]);
    }
    // read 1 byte with offset 9 back from the image at slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_ReadRegister(9, 1, &Dummy[9]);
    }
    // write 2 bytes with offset 0 from Dummy filed to slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_WriteRegister(0, 2, &Dummy[0]);
    }
    // read 2 bytes with offset 0 back from the image at slave memory
    if(tout()) {
      set_tout_ms(10);
      I2C_ReadRegister(0, 2, &Dummy[0]);
    }
    // if a timout error occures switch on LED2 
    if(!tout())
      switch_on(LED2);
		// switch off LED1 at the end of test
    switch_off(LED1);
    // check if dummy field is not corrupted => switch on LED 4 if test not successful   
    if(memcmp(Dummy, DUMMY_INIT, MAX_DUMMY) != 0)
      switch_on(LED4);
    delay(1);
  }
}
Beispiel #17
0
void FM_SetVolume(uint16_t level){
	I2C_WriteRegister(SI4703, SYSCONFIG2, level);
}
void IMU_gyro_init(void) {
    I2C_WriteRegister(ITG_ADDRESS, ITG_PWR_MGM, 0x80); // H_RESET
    I2C_WriteRegister(ITG_ADDRESS, ITG_DLPF_FS, 0x18); // DLPF_CFG = 0, FS_SEL = 3
    I2C_WriteRegister(ITG_ADDRESS, ITG_PWR_MGM, 0x00); // RESET off
}
void MAX3353_Write_Register(uint_8 u8Register, uint_8 u8Value)
{
    I2C_WriteRegister(MAX3353_I2C_ADDRESS,u8Register,u8Value);
}
void IMU_accel_init(void) {
    I2C_WriteRegister(ADXL_ADDRESS, ADXL_BW_RATE, 0x0e); // 1600 Hz ODR, 800 Hz Bandwidth
    I2C_WriteRegister(ADXL_ADDRESS, ADXL_POWER_CTL, 0x08);
    I2C_WriteRegister(ADXL_ADDRESS, ADXL_DATA_FORMAT, 0x09); // Full res, +-4g
}