01-19-2022 12:31 PM
Hello there!
I´m trying get CHIP-ID using SPI MCC library and i dont know corretly how to use the following void:
uint8_t SPI1_ExchangeByte(uint8_t data)
{
SSP1BUF = data;
while(!PIR3bits.SSP1IF);
PIR3bits.SSP1IF = 0;
return SSP1BUF;
}
I tryed it like that:
readDummyp = SPI1_ExchangeByte(0X00);
But it recieve 0x85 and i dont know what it means.
regrets.
01-19-2022 02:08 PM
01-19-2022 04:53 PM
02-08-2022 04:20 AM
Hello JFdez007,
You could refer to the code logic of the sensor API, activate the SPI interface first, and then read the chip ID via SPI.
As you used SPI library, you could call the library and capture SPI waveform to check if the actual SPI communication is normal.
/*!
* @brief This API is the entry point for sensor.It performs
* the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id of bmi160 sensor.
*/
int8_t bmi160_init(struct bmi160_dev *dev)
{
int8_t rslt;
uint8_t data;
uint8_t try = 3;
/* Null-pointer check */
rslt = null_ptr_check(dev);
/* Dummy read of 0x7F register to enable SPI Interface
* if SPI is used */
if ((rslt == BMI160_OK) && (dev->intf == BMI160_SPI_INTF))
{
rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev);
}
if (rslt == BMI160_OK)
{
/* Assign chip id as zero */
dev->chip_id = 0;
while ((try--) && (dev->chip_id != BMI160_CHIP_ID))
{
/* Read chip_id */
rslt = bmi160_get_regs(BMI160_CHIP_ID_ADDR, &dev->chip_id, 1, dev);
}
if ((rslt == BMI160_OK) && (dev->chip_id == BMI160_CHIP_ID))
{
dev->any_sig_sel = BMI160_BOTH_ANY_SIG_MOTION_DISABLED;
/* Soft reset */
rslt = bmi160_soft_reset(dev);
}
else
{
rslt = BMI160_E_DEV_NOT_FOUND;
}
}
return rslt;
}