09-28-2021 11:11 AM
Hello,
we are using BMA456, connected to a uC via SPI Interface.
In first step, I simply want to read the acceleration data registers, and I wrote a small program according to the steps described in "Example 2" of the data sheet.
But the readout of the registers is always Zero.
What am I doing wrong, resp. what do I have to do to make it work ? Is there any further initialisation/configuration necessary ? If so, does anybody have a code example for this ?
I downloaded the driver API, but there is a lot of code inside which I do not (yet) understand.
I searched the net carefully, but could not find any help or information....
Thanks in advance, bye
Harald
Solved! Go to Solution.
10-04-2021 10:32 AM
Hello again,
I migrated the acceleration example project to my hardware, but unfortunately it does not work correctly...
I can see that in lines 921+922 of module bma4.c:
rslt = bma4_read_regs(BMA4_INTERNAL_STAT, &config_stream_status, 1, dev);
config_stream_status = config_stream_status & BMA4_CONFIG_STREAM_MESSAGE_MSK;
the content of variable config_stream_status is 0 after execution of function bma4_read_regs(...). This seems to signal an error.
Sorry, but I do not exactly understand what this function does, but I believe it could be a problem of my implementation of functions user_spi_read(...) and
user_spi_write(...).
I implemented the following code by use of HAL SPI functions. Could you please check if there is something wrong ?
I assume the code in user_spi_write() is possibly not correct. On call of the function I first transmit one byte of adress data, after the register data with given length. Is that okay ?!
/*!
* @brief Function for writing the sensor's registers through SPI bus.
*/
int8_t user_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Implement the SPI write routine according to the target machine. */
HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_RESET); // NSS Pin = Low
HAL_SPI_Transmit(&hspi2,®_addr,1,100); // Transmit Register Adress
HAL_SPI_Transmit(&hspi2,(uint8_t *)reg_data,length,100); // Transmit Data
HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_SET); // NSS Pin = High
return 0;
}
/*!
* @brief Function for reading the sensor's registers through SPI bus.
*/
int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Implement the SPI read routine according to the target machine. */
HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_RESET); // NSS Pin = Low
HAL_SPI_TransmitReceive(&hspi2,®_addr,reg_data,length,100);
HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_SET); // NSS Pin = High
return 0;
}
Thank you in advance, kind regards
Harald
10-04-2021 10:52 AM
Hello again,
it's okay now, I found the problem. The use of HAL_SPI_TransmitReceive in function user_spi_read() was wrong. I replaced it by
HAL_SPI_Transmit(&hspi2,®_addr,1,100); // Transmit Register Adress
HAL_SPI_Receive(&hspi2,reg_data,length,100); // Receive Register Data
and now it works....it seems, the second dummy write byte of adress transfer is included in the receive data length, or not ?
However, now it works and that's great 🙂
Thanks a lot for your assistance
Harald
11-03-2021 07:17 AM
Hello HBUDE,
HAL_SPI_TransmitReceive() also could work. You could refer example code I uploaded in another ticket: https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMA456-Init-fail/m-p/47081#M8520
11-03-2021 08:36 AM
Hello BSTRobin,
thanks for information. I know it's working, I simply used the wrong data length in this function.
Thanks again, bye
Harald