This article details the SPI communication setup between S32K1xx boards and MC3377xBSPI Battery Cell Controllers. It covers both hardware and software setup for the Battery Management System models designed using Model-Based Design Toolbox for battery packs up to 14 cells in series. At the end of this article, the user will be able to setup the Battery Cell Controller hardware and to design a Simulink model that reads the cell and pack voltages, current, temperatures and faults status. The measured values will be displayed on the host PC using FreeMaster.
MC3377xBSPI is a Battery Cell Controller family that manages battery packs up to 14 Li-Ion cells in series. The BCC (Battery cell Controller) communicates with the main MCU over the classic SPI communication.
This Batter Cell Controller comes in two derivatives.
Even though the hardware setup is very similar for both derivatives and we could detail the setup only for one of them, we will mention the hardware parts and settings for each of the derivatives.
Before going to the next step, the solder jumpers for the FRDM33771BSPIEVB board must be configured in order to make it compatible with the S32K144EVB. This process is detailed both in the UM1143 [4.1] Table 1 or User-Guide [4.2] Table 16. Jumper setting to work with S32K144EVB. The JP26 & JP36 must be unsoldered while the JP27 (1-2), JP37 (1-2), JP39(2-3) and JP43(2-3) must be resoldered. Without these settings, the communication on the EVBs will be unsuccessful.
Before going to the next step, the solder jumpers for the FRDM33772BSPIEVB board must be configured in order to make it compatible with the S32K144EVB. This process is detailed both in the UM1143 [4.1] Table 3 or User-Guide [4.3] Table 11. Jumper setting to work with S32K144EVB. The J26 & J36 must be unsoldered while the J27 (1-2), J37 (1-2), JP30(2-3) and JP32(2-3) must be resoldered. Without these settings, the communication on the EVBs will be unsuccessful.
This step is common for both cases presented in the previous chapter. Before following the next steps, be sure that your board has all the jumpers soldered correctly as described previously.
Be aware that the MC3377xB chip is powered up by the cells, in our case the Emulator. The emulator has to be powered up in order to have successfully communication between the BCC and the main MCU. The final setup will look like this.
In this section, we are going to detail the settings of the blocks required to configure and achieve data from the battery cell controller, connected over the SPI peripheral.
3.1 General/Boards Configuration Blocks
For all the models that generate code for the S32K1xx microcontrollers, the MBD_S32K1xx_Config_Information must be added inside the model. In this block, the user selects the controller for which Simulink will generate code, the compiler, and the deploying way of the generated code on the target.
The FreeMaster Config block needs to be added in the model to configure the FreeMaster and the peripheral used for communication, between UART or CAN. For this model, we are going to use the LPUART 1 peripheral.
3.2 Battery Cell Controller Configuration Blocks
To accomplish a successful communication between the S32K and MC3377xBSPI block we firstly must add an LPSPI Configuration block in our model. This will initialize the LPSPI peripheral and will configure the pins selected for the communication. For this application, we can select only the right pins for the LPSPI and leave the communication parameters default. In the MC3377xB_Config block, there is a button that, once pressed, will set the right parameters for the BCC communication in the LPSPI Config Block.
The MC3377xB_Config block initializes the Battery Cell Controller.
In the Configuration TAB, the user must choose the communication mode (SPI/TPL), the device type (MC33771B/MC33772B), and the Cell number connected to the Battery Cell Controller.
The SPI tab refers to the LPSPI peripheral. In the case of the SPI communication mode, only one LPSPI instance is required. The dropdown options will be populated only after one of the LPSPI Configuration blocks were added to the model displaying their instance number. Here the user must set the Chip Select pin number that is going to be used for BCC selection during communication. If the user presses on the “Config for BCC as Master” button, then the right values will be set in the LPSPI Config block.
The last tab lets the user specify the NTC thermistors characteristics and the shunt resistance value. These values are used by the MC3377xB_GetValues block, to automatically convert the RAW values, provided by the Battery Cell Controllers into values delivered in common measure units like Amps and *C. If the user wants to read only the RAW values and not to automatically convert the block, this tab must be ignored.
In this section, we are going to detail two modes in which the values converted by the Battery Cell Controllers can be transferred to the main MCU via the SPI connection.
The first method uses MC3377xB_Get_Values Block. As you can see in the previous image, this block returns all the measured values directly in Volts, Amps, and degrees Celsius. The conversions from RAW values are based on the parameters inserted in the Pack Settings tab of the MC3377xB_Config. The Cells Voltage returns always a 14 uint32 array, the maximum cells number. The user must ignore the values that are not used. The same scenario is applied for the NTC Temperatures because the MC3377xB can measure up to 7 thermistors.
The MC3377xB_Get_Values block has the following options:
For reading the raw values, then the following approach can be used.
3.4 Faults reading
The Battery Cell Controller monitors have fault status registers in which notifies unusual behavior. Getting the Fault status values to the microcontroller is possible using the MC3377xB_Fault_Get_Status. This will return an 11 uin16_t array containing the fault status registers. The understand the error flags from the registers please have a look at the MC3377xB Reference Manual.
As you have probably noticed already, each of the blocks has an output called Status. This output provides the status output for the current operation. It can notify the user regarding if the transfer is not successful, either if the SPI instance is busy, or there is a timeout, communication CRC error or the communication is successful and there is no error. All the error values are detailed in each of the blocks Help page.
This article comes with the examples described above. Running the models on your setup could be a good starting point for your project. Once the code has been successfully generated and deployed on the target, the FreeMaster can be connected to the board via UART and the values can be monitored on the Host PC, just like in the application below.
5.2. FRDM33771BSPIEVBUG https://www.nxp.com/docs/en/user-guide/FRDM33771BSPIEVBUG.pdf
5.3. FRDM33772BSPIEVBUG https://www.nxp.com/docs/en/user-guide/FRDM33772BSPIEVBUG.pdf