Esempio n. 1
0
int main()
{
  
  //create i2c bus. the 0 indicates pull up resistors are present on the i2c line
  DofBus = i2c_newbus(DofSCL, DofSDA, 0);
  
  
  unsigned char ID = 2;
  int val = i2c_in(DofBus, GyroAddr, 0x00, 1, (unsigned char*)ID, 1);
  //get device ID with i2c read
  
  print("ID readback: 0x%x", ID);
  
  char temp[5];
  pause(100); //allow gyro clocks to stabalise

  //start hyperterminal menu
  hyperterminal();
  
  
  while(1)
  {
      
     
  }


  return 0;
}
int main()                                    // Main function
{
  eeBus = i2c_newbus(28,  29,   0);           // Set up I2C bus, get bus ID

                                              // Use eeBus to write to device
  i2c_out(eeBus, 0b1010000,                   // with I2C address 0b1010000,
          32768, 2, "abcdefg", 8);            // send address 32768 (2 bytes)
                                              // and "abc..." data (8 bytes)

  while(i2c_busy(eeBus, 0b1010000));          // Wait for EEPROM to finish  

  char testStr[] = {0, 0, 0, 0, 0, 0, 0, 0};  // Set up test string   

                                              // Use eeBus to read from device
  i2c_in(eeBus, 0b1010000,                    // with I2C address 0b1010000,
         32768, 2, testStr, 8);               // send address 32768 (2 bytes)
                                              // data in to testStr (8 bytes)

  print("testStr = %s \n", testStr);          // Display result
}
int main()                                    // main function
{
  int x, y, z;                                // Declare x, y, & z axis variables
  
  i2c *bus = i2c_newbus(3, 2, 0);             // New I2C bus SCL=P3, SDA=P2
  compass_init(bus);                          // Initialize compass on bus.

  while(1)                                    // Repeat indefinitely
  {
    compass_read(bus, &x, &y, &z);            // Compass vals -> variables
    print("%cx=%d, y=%d, z=%d%c\n",           // Display compass variables
           HOME, x, y, z, CLREOL);

    float fy = (float) y;                     // Ints to floats
    float fx = (float) x;
    float heading = atan2(fy, fx) * 180.0/PI; // Calculate heading with floats
    if(heading < 0.0)                         // Convert -180...+180 to 0...360
      heading = (360.0 + heading);
    print("heading = %.2f%c\n",               // Display heading
                        heading, CLREOL);       

    pause(500);                               // Wait 1/2 second
  }
}
void ee_config(int sclPin, int sdaPin, int sclDrive)
{
  st_eeprom = i2c_newbus(sclPin, sdaPin, sclDrive);
  st_eeInitFlag = 1;
}
Esempio n. 5
0
void ee_init()
{
  st_eeprom = i2c_newbus(28, 29, 0);
  st_eeInitFlag = 1;
}