Unable to communicate with BMI055 through SPI

Hello! I am currently making a little datalogger board to fly inside model rockets. In short, the board has an ATTINY 824 which should collect data from the BMI055 IMU to then write it in a flash chip for the duration of the flight. Once the device detects a landing it moves the data into an SD card. So far I've been able to upload test sketches which blink the interface LED's on the board. I've since moved on to attempt SPI communication with the IMU, but I can't get it to read the IMU's gyro chip ID. I am using the interface LED's to read the values received through SPI, and every time I attempt to read the gyro chip ID, I get the binary value 11111111 (255) instead of the expected 00001111 (15), which I think indicates that the gyro is not understanding the command and is just leaving the MISO line idle. Here is the code that runs this, for reference:

  digitalWrite(PIN_PA7, LOW);
  receivedData = (SPI.transfer(0x00))/5;     /*I divide the value by 5 because otherwise I would have to count 255 blinks to read the max binary value*/
  digitalWrite(PIN_PA7, HIGH);

I read the BMI055 datasheet as well, and I tried to enter the SPI read instruction as they defined it by using the first bit as a R/W indicator and the remaining 7 as an address.

digitalWrite(PIN_PA7, LOW);
  receivedData = (SPI.transfer(0b10000000))/5;    /*I divide the value by 5 because otherwise I would have to count 255 blinks to read the max binary value of 11111111*/
  digitalWrite(PIN_PA7, HIGH);
  delay(500);

I have also tried to run the code in two separate boards but still have no luck, so I think I can rule out faulty hardware. Here are all the schematics, datasheets, code, and other info that may be useful (the forum does not let me upload attachments since I am a new user so I uploaded them to a google drive folder):

https://drive.google.com/drive/folders/15rwWyw8nzJLBnM5iWjcLNbN-B7tYJpz3?usp=sharing

I am relatively new to embedded design so any critiques on my schematic are always welcome too :smile:

You should always post complete code. In most cases the error is in that part of the code people are hiding from us.

In this excerpt the delay() calls isn't necessary and can be removed.

You first have to send the read command and then read the result. This chip cannot know what you expect it to do before you tell it so.

Thanks for the response! I already posted the entire arduino file in the google drive folder linked at the end of the post. Also, the delay command is necessary to allow me to count the interface LEDs blinking. Let me know if there’s anything you find in the files

Oh almost forgot, for this device, according to what I read in the data sheet, I read that instead of an op code for reading/writing thru SPI you have to set the first bit high/low depending if you want to read or write from the register address.

Always post code to this forum. I don't look at temporary storage because future visitors won't find anything there and ask the same question again.

Take a look at figure 22 of the datasheet. The first byte is completely sent before anything is sent back by the device. So you get the reply in the second transfer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.