Skip to content

Instantly share code, notes, and snippets.

@davisford
Created January 31, 2013 17:33
Show Gist options
  • Select an option

  • Save davisford/4684630 to your computer and use it in GitHub Desktop.

Select an option

Save davisford/4684630 to your computer and use it in GitHub Desktop.
int accel_spi_init()
{
if (bcm2835_init() != 1)
{
perror("Could not initialize BCM2835 library");
return -1;
}
// enable SPI for accelerometer
bcm2835_spi_begin();
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128);
bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
return 0;
}
// other functions here to read/write accelerometer
int power_spi_init()
{
if (bcm2835_init() != 1)
{
perror("Could not initialize BCM2835 library");
return -1;
}
// enable SPI for accelerometer
bcm2835_spi_begin();
bcm2835_spi_setDataMode(BCM2835_SPI_MODE1);
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_8192);
bcm2835_spi_chipSelect(BCM2835_SPI_CS1);
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, HIGH);
return 0;
}
// other functions here to read/write power management
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment