Introduction
The following article shows a basic configuration and model for S32K396BMS-EVB that configures the SPI to communicate with the MC33CD1030 MSDI IC mounted on the evaluation board.
Prerequisite software
The following software tools were used to develop and deploy the application onto the S32K396BMS-EVB board.
Prerequisite hardware
The application is developed for the following hardware*:
- S32K396BMS-EVB
- Debug probe (used to deploy the example and to connect the FreeMASTER application to the board)
- 12V power supply
Configuration project
In this chapter, I show most important settings that must be to allow the MCU to enter standby mode and to be able to wake up and switch to RUN mode again. For more details, please download the files attached and consult the configuration project.
Pins configuration
For the CD1030, only the SPI pins must be configured;
- LPSPI3 PCS1: PTF18 (OUTPUT)
- LPSPI3 CLOCK: PTF13 (OUTPUT)
- LPSPI3 SIN: PTF12 (INPUT)
- LPSPI3 SOUT: PTF15 (OUTPUT)
Figure 1. Configuration Pins tab - LPSPI pins
Peripherals configuration
Platform component
The interrupt must be configured for the LPSPi3. To configure it, please go to PLATFORM -> Interrupt Controller and add a new entry into the table, as below.
Figure 2. Configuration Platform Component - Enable LPSPI3 interrupt
MCU Component
The peripheral clock must be enabled and it can be done from the MCU component -> McuModuleConfiguration -> McuModeSettingsConf.
Figure 3. Configuration MCU Component - Enable LPSPI3 peripheral clock
SPI Component
The MCU communicates with MC33CD1030 over the LPSPI3. First step is to configure the Spi -> SpiGeneral -> SpiPhyUnit
Figure 4. Configuration SPI Component - SpiPhyUnit (LPSPI3)
Then, the Spi->SpiDriver must be configured.
Important! The frame size of the SPI messages: It must be 32-bit wide and MSB.
Figure 5. Configuration SPI Component - SpiChannel
Figure 6. Configuration SPI Component - SpiExternalDevice
Figure 7. Configuration SPI Component - SpiJob
Figure 8. Configuration SPI Component - SpiSequence
Model configuraiton
The Simulink model used to communicate with the MC33CD1030 can be seend in the picture below. It can also be found in the achieve attached to this article.
The initialization of the model sets the AsyncMode to interrupt.
Figure 9. Simulink Model - Initialization subsystem
The application executes the following tasks at each step:
- Set up the External Buffer for the LPSPI3 SpiChannel_CD1030. The input for the block must be an array of 4 uint8 elements (in total 4 bytes - 32bit). The control word is the last element, while the first 3 elements are the configure words. The Dest Data output is a data story memory configured as uint8 with the size equal to 4.
- Send the command to the MC33CD1030 IC and receive the previous result in CD1030_RecvData_SG data store
- Increment a variable to check that the application is running
Figure 10. Simulink Model - Full Overview
Validation
To validate the application, the FreeMASTER tool is used to connect to the board and initiate the sequence to enter standby mode. To connect the board, you can use the LPUART1 (J6 connector), baud rate 115200.
If everything is properly configured, in the FreeMASTER you should see the following in the Variable Watch:
- The SPI_SetAsyncMode_Status, CD1030_SetupEB_Status and SPI_Transmit_Status should all be 0.
- The CD1030_RecvData_SG (BIN) and CD1030_RecvData_SG (HEX) should display the content of the CD1030's register 0x3E Read switch status registers SG.
- The step_counter should increment at each step execution.
Figure 11. FreeMASTER Project - Variable Watch
To test that the CD1030 is working, I connect the J10_6 (SG0 - KEY_ON_DIN) to either GND or VCC and we can see that the last bit of the register changes.
Figure 12. FreeMASTER Project - J10_6 connected to GND
Figure 13. FreeMASTER Project - J10_6 connected to VCC
Conclusion
In this article, I presented a basic implementation that allows the S32K396 communicate with the MC33CD1030 IC over the SPI. For further details, please consult the MC33CD1030 reference manual.