Preliminary Technical Data
UG-1828
Rev. PrC | Page 39 of 338
if (!bcm2835_spi_begin())
{
printf("bcm2835_spi_begin failed. Are you running as root??\n");
return 1;
}
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32768); // 12kHz
bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); //
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH); // The default
// Set the CE pin to be an output
bcm2835_gpio_fsel(CE_PIN, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(CE_PIN, HIGH);
delay(1);
return 0;
}
int32_t customer_adi_adrv9001_hal_close(void *devHalCfg)
{
/* Customer code goes here */
bcm2835_spi_end();
return 0;
}
int32_t customer_adi_adrv9001_hal_spi_write(void *devHalCfg, const uint8_t txData[], uint32_t numTxBytes)
{
/* Customer code goes here */
bcm2835_gpio_write(CE_PIN, LOW);
delay(1);
bcm2835_spi_begin();
bcm2835_spi_transfern(txData, numTxBytes);
bcm2835_spi_end();
delay(1);
bcm2835_gpio_write(CE_PIN, HIGH);
return 0;
}
int32_t customer_adi_adrv9001_hal_spi_read(void *devHalCfg, const uint8_t txData[], uint8_t rxData[], uint32_t numTxRxBytes)
{
/* Customer code goes here */
bcm2835_gpio_write(CE_PIN, LOW);
delay(1);
bcm2835_spi_begin();
bcm2835_spi_transfernb(txData, rxData, numTxRxBytes);
bcm2835_spi_end();