Arduino Uno SPI communication with MC33771B battery cell controller. BMS Project

Hey Arduino Team,
I am working on an important project would like your help figure out a major technical challenge. We are trying to interface a arduino uno with FRDM33771BSPIEVB MC33771B battery cell controller IC over SPI communication. It is possible to interface them both over SPI but we are not quite able to get accurate data from the NXP.

The MC33772B SPI interface is a standard SPI slave interface with a chip select (CSB),
clock (SCLK), Slave Out (SO), and Slave In (SI). The SI/SO shifting of the data follows a
first-in-first-out protocol, with both input and output words transferring the Most Significant Bit (MSB) first.
All SPI communication to the MC33772B is controlled by the microcontroller. One 40-bit
register of previously requested data is retrieved through serial out for each current serial
in message sent by the MCU. For message integrity and communication robustness,
each SPI transmit message consists of six fields containing 40 bits.
The six transmit fields are defined as the following:

  1. Cyclical redundancy check (8 bits)
  2. Command field (4 bits)
  3. Cluster ID field (4 bits)
  4. Memory address field (7 bits)
  5. Master/slave field (1 bit)
  6. Memory data field (16 bits)
    SPI: Master mode, 40 bits/frame, MSB first, clock polarity: active low, clock phase:
    capture on the 2nd edge, clock frequency: up to 4.2 MHz
    • SPI CSB (SW controlled chip select): GPIO output pin, active low, initial value: high
    • RST (optional): GPIO output pin

So since NXP MC33771B battery cell controller IC sends 40 bits = 5 bytes. I am only receiving the 5th Byte and missing the rest. This is my code. `#include <SPI.h>

// Define the Chip Select pin for the MC33771B
const int CSB_PIN = 10; // Adjust to your specific pin

// SPI Settings (4 MHz, MSB first, SPI mode 0)
SPISettings settings(4200000, MSBFIRST, SPI_MODE0);

// Function to receive a 40-bit message from MC33771B
uint64_t receive40BitMessage() {
uint64_t receivedData = 0;

// Start SPI transaction
SPI.beginTransaction(settings);
digitalWrite(CSB_PIN, LOW);
delay(1000);

// Receive the 40-bit message (5 bytes)
for (int i = 0; i < 5; i++) {
receivedData = (receivedData << 8) | SPI.transfer(0x00);
}

// End SPI transaction
digitalWrite(CSB_PIN, HIGH);
delay(1000);
SPI.endTransaction();

return receivedData;
}

void setup() {
// Initialize the CSB pin and set it high (device not selected)
pinMode(CSB_PIN, OUTPUT);
digitalWrite(CSB_PIN, HIGH);

// Begin SPI communication
SPI.begin();

// Initialize Serial communication for printing
Serial.begin(115200);
}

void loop() {
// Receive response from MC33771B
uint64_t response = receive40BitMessage();

// Print the received 40-bit data
Serial.print("Received data: 0x");
Serial.print((uint32_t)(response >> 32), HEX); // Print upper 32 bits
Serial.println((uint32_t)response, HEX); // Print lower 32 bits

delay(1000); // Wait before the next communication
}` I understand it is a hard topic which I am trying to achieve, but I am willing to pay for the help if it gets the work done. This project is super important to me.

Thank you for your time
Shubhay D
email - shubhay@mexatechinnovations.comThe NXP board I am using