10-01-2020 07:24 AM
Hello.
FOr some reason i can't read any meaningfull registers, as well as chip ID, reading from 0 ADR gives 0xFF
My read code is like this:
of AC:
CSA LOW
SEND(ADR+1) // Does adress need to be shifter ?
SEND(0)//DUMMY
DATA=SEND(0) // Sending someting to read data
CSA HIGH
for GYRO:
CSG_LOW
SEND(ADR+1) // Does adress need to be shifter ?
DATA=SEND(0) // Sending someting to read data
CSG_HIGH
But if i try to read ADR = 170, it does give some 0xE8 value.
Any idea what i am doing wrong ? (CLK is below 1MHz for SPI)
Datasheet could not give less information about SPI. no diagrams, no normal examples. even no normal register definition, just use our own API and don't ask questions.
Solved! Go to Solution.
10-01-2020 06:00 PM
Very nice Bosh, very nice. So while reading forum i noticed, that read bit is not LSB, but MSB !!!!
Now lets see what datasheet is saying:
So bit zero is actually 0x80 or 10000000.
Switched code for MSB bit for read operation, and what do you know, right answer in first time 🙂
Pseudo code:
CSA LOW
SEND(ADR | 0x80)
SEND(0)//DUMMY
DATA=SEND(0)
CSA HIGH
STM32L5 code:
uint8_t BMI085_Read_Register_ACC(uint8_t adr)
{
uint8_t data = 0;
SPI1_CSG_GPIO_Port->HIGH = SPI1_CSA_Pin|SPI1_CSG_Pin;
SPI1_CSG_GPIO_Port->LOW = SPI1_CSA_Pin;
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
SPI1_Send_Recieve_byte(adr|0x80);
SPI1_Send_Recieve_byte(0);
data = SPI1_Send_Recieve_byte(0);
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
SPI1_CSG_GPIO_Port->HIGH = SPI1_CSA_Pin|SPI1_CSG_Pin;
return data;
}
Please fix datasheet and add some complete SPI timing diagram. Just as i suspected, extremely poorly written datasheet !
10-01-2020 06:06 PM
Hi,
Thanks for your inquiry.
BMI085 supports SPI mode 0 and 3. The gyro part is staight forward. When you send 0x80 to read gyro chip ID at adress of 0x00, then you will immediately get the correct value of 0x0F back. For accel part after you send 0x80 to read accel chip ID at address of 0x00, you will get a dummy byte back. After you send another any byte such as 0x00 or 0xFF, you will get the correct value of 0x1F back.
Please refer to the SPI interface part for BMA456 on page 81 at https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bma456-ds000.pdf for more information.
Thanks.
10-01-2020 07:52 PM
Yes, this is correct. But datasheet says different things. When i figure out this part, it start working, and all my code works. I was bale to get ac and gyro data with no API , so far so good.
Please inform bosh who is making datasheet to include spi diagram and correct erros how to read/write data since it has wrong definition for write bit.
in your linked pdf it's correct 🙂
Thank you !