Beispiel #1
0
void WM8960_WriteData(Uint8 channel, Uint8 Register, Uint16 Data)
{
  Uint8 HightByte,LowByte;
  Uint8 I2C_Status;
  HightByte = Data >> 8;
  HightByte = HightByte & 0x01;
  HightByte |= (Register << 1);

  LowByte = Data; //bit 7 - 0

  IIC_Start(channel);
  IIC_Delay();
  if(!(IIC_WriteByte(channel,WM8960_Write_ADD)))
  {
    I2C_Status =  IIC_WriteByte(channel,HightByte);
    I2C_Status = IIC_WriteByte(channel,LowByte);
    IIC_Delay();
    IIC_Stop(channel);

#if DebugVerbosity > 1
    if(I2C_Status == 0)
    {
      UART_TxStr("Channel = ");
      UART_TxUint8(channel);
      UART_TxStr("Register = ");
      UART_TxUint8(Register);
      UART_TxStr(" Value = ");
      UART_TxUint8(Data>>8);
      UART_TxUint8(LowByte);
      UART_TxStr("\n\r");
    }
//HELPER FUNCTIONS==============================================================================
void DSPC01::send_SPC01_write_command(unsigned char command)  
{  
      IIC_Start();  
      communicate_status = IIC_WriteByte(0x20);  
      if( communicate_status == COMMUNI_SUCCEED)  
      {  
            communicate_status = IIC_WriteByte(command);     
            if( communicate_status == COMMUNI_SUCCEED)  
            {  
                  IIC_Stop();  
            }       
      }       
}       
unsigned int DSPC01::compass(void)  
{  
  unsigned int comp=0;   
  IIC_Start();  
  communicate_status = IIC_WriteByte(0x21);  
  if( communicate_status == COMMUNI_SUCCEED)  
  {  
    comp+= (unsigned long int)(IIC_ReadByte()<<8);
    IIC_ACK();     
    comp+=IIC_ReadByte();        
    IIC_NoAck();  
    IIC_Stop();   
  }  
  return comp;           
}  
long int DSPC01::temperature(void)  
{  
  long int temp=0;  
  IIC_Start();  
  communicate_status = IIC_WriteByte(0x21);  
  if( communicate_status == COMMUNI_SUCCEED)  
      {  
            temp +=(unsigned int)(IIC_ReadByte()<<8);
            IIC_ACK();  
            temp +=IIC_ReadByte();              
            IIC_NoAck();  
            IIC_Stop();  
      }  
  if (temp>32768) 
  temp = 32768-temp;
  return temp; 
}  
unsigned long int DSPC01::pressure(void) 
{
  unsigned long int press_temp=0;
  IIC_Start();  
  communicate_status = IIC_WriteByte(0x21);  
  if( communicate_status == COMMUNI_SUCCEED)  
  {  
    press_temp = IIC_ReadByte(); 
    press_temp*=256; 
    press_temp*=256;
    IIC_ACK();                
    press_temp+= (unsigned int)(IIC_ReadByte()<<8);  
    IIC_ACK();               
    press_temp+= IIC_ReadByte();  
    IIC_NoAck();  
    IIC_Stop();  
  } 
  return press_temp;
}
long int DSPC01::altitude(void) 
{
  long int alt_temp=0;
  IIC_Start();  
  communicate_status = IIC_WriteByte(0x21);  
  if( communicate_status == COMMUNI_SUCCEED)  
      {  
            alt_temp = IIC_ReadByte(); 
            alt_temp*=256; 
            alt_temp*=256;
            IIC_ACK();                
            alt_temp+= (unsigned int)(IIC_ReadByte()<<8);  
            IIC_ACK();               
            alt_temp+= IIC_ReadByte();  
            IIC_NoAck();  
            IIC_Stop();  
      } 
  if (alt_temp>8388608) //negative!
  alt_temp=8388608-alt_temp;
  return alt_temp;
}