Hi NXP Team,
I am using the NXP S32K144 board and trying to communicate with the UJA1169 SBC through SPI communication. My goal is to read the Manufacturer ID register from the SBC.
For this, I have written the SPI communication code, which I am attaching below for reference. According to the schematic, I have selected the LPSPI1 instance with the following pin configuration:
PTB14 → SCK
PTB15 → SIN
PTB16 → SOUT
PTB17 → PCS3
I have also attached the screenshots of the SPI driver settings configured in the MEX file.
However, I am not able to receive any valid data from the UJA1169 SBC. The SPI clock is getting generated, but the receive data is not coming properly from the SBC side.
Can anyone help me identify where I might have made a mistake in the SPI configuration or communication sequence?
Below is my code for reference:
/*
* Copyright 2020 NXP
*
* NXP Confidential. This software is owned or controlled by NXP and may only be used strictly
* in accordance with the applicable license terms.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*==================================================================================================
* INCLUDE FILES
==================================================================================================*/
#include "Mcu.h"
#include "Port.h"
#include "Spi.h"
#include "Platform.h"
#include "spi_cfg.h"
/*==================================================================================================
* LOCAL VARIABLES
==================================================================================================*/
#define UJA1169_ID_REGISTER (0x7EU)
#define UJA1169_READ_COMMAND(reg) ((uint8)(((reg) << 1U) | 0x01U))
/* The S32K144EVB schematic uses UJA1169TK/F, whose identification value is 0xEF. */
#define UJA1169_EXPECTED_ID (0xEFU)
/* SPI transfer completion flag */
volatile boolean SpiTransferDone = FALSE;
/* Keep the result global so it is easy to inspect in the debugger. */
volatile uint8 Uja1169DeviceId = 0U;
/*==================================================================================================
* GLOBAL FUNCTIONS
==================================================================================================*/
/* SPI transfer complete callback */
void SpiJobEndNotification(void)
{
SpiTransferDone = TRUE;
}
static Std_ReturnType Uja1169_ReadRegister(uint8 RegisterAddress, uint8 * RegisterValue)
{
Std_ReturnType Status;
uint8 TxBuffer[4] = {0U, 0U, 0U, 0U};
uint8 RxBuffer[4] = {0U, 0U, 0U, 0U};
if (NULL_PTR == RegisterValue)
{
return E_NOT_OK;
}
/*
* UJA1169A SPI command byte: address[7:1] + read bit[0].
* Register 0x7E read command is 0xFD. Four bytes are used because the
* current SpiChannel_SBC configuration is 32-bit; the SBC supports 32-bit SPI.
*/
TxBuffer[0] = UJA1169_READ_COMMAND(RegisterAddress);
SpiTransferDone = FALSE;
Status = Spi_SetupEB(SpiConf_SpiChannel_SpiChannel_SBC, TxBuffer, RxBuffer, 4U);
if (E_OK != Status)
{
return Status;
}
Status = Spi_AsyncTransmit(SpiConf_SpiSequence_SpiSequence_1);
if (E_OK != Status)
{
return Status;
}
while(FALSE == SpiTransferDone)
{
}
/* The selected register value is returned during the first data byte. */
*RegisterValue = RxBuffer[1];
return E_OK;
}
/**
* @brief Main function
*/
int main(void)
{
Std_ReturnType Status;
uint8 DeviceId = 0U;
/* Initialize MCU */
#if (MCU_PRECOMPILE_SUPPORT == STD_ON)
Mcu_Init(NULL_PTR);
#elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
Mcu_Init(&Mcu_Config_VS_0);
#endif
/* Initialize clock */
Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
while (MCU_PLL_LOCKED != Mcu_GetPllStatus())
{
/* Wait for PLL lock */
}
Mcu_DistributePllClock();
#endif
Mcu_SetMode(McuModeSettingConf_0);
/* Initialize Port */
Port_Init(NULL_PTR);
/* Initialize Platform */
Platform_Init(NULL_PTR);
/* Initialize SPI */
Spi_Init(NULL_PTR);
/* Set SPI interrupt mode */
Status = Spi_SetAsyncMode(SPI_INTERRUPT_MODE);
if (E_OK != Status)
{
while(1)
{
}
}
Status = Uja1169_ReadRegister(UJA1169_ID_REGISTER, &DeviceId);
Uja1169DeviceId = DeviceId;
if ((E_OK != Status) || (UJA1169_EXPECTED_ID != Uja1169DeviceId))
{
while(1)
{
}
}
while(1)
{
}
return (0U);
}
#ifdef __cplusplus
}
#endif
I would appreciate your support in identifying the issue. Please let me know if any additional information, screenshots, or logic analyzer captures are required from my side.
Looking forward to your reply as soon as possible.
Thank you.S32K144 Schematic Diagram PinsS32K144 Schematic Diagram PinsS32K144 Schematic Diagram PinsS32K144 Schematic Diagram PinsS32K144 Schematic Diagram PinsS32K144 Schematic Diagram PinsS32K144 Schematic Diagram Pins
SPI Clock SettingSPI Clock SettingSPI Clock SettingSPI Clock SettingSPI Clock SettingSPI Clock SettingSPI Clock Setting
Pin mappingPin mappingPin mappingPin mappingPin mappingPin mappingPin mapping
Port setting Pic1Port setting Pic1Port setting Pic1Port setting Pic1Port setting Pic1Port setting Pic1Port setting Pic1
Port setting Pic2Port setting Pic2Port setting Pic2Port setting Pic2Port setting Pic2Port setting Pic2Port setting Pic2
Port setting Pic3Port setting Pic3Port setting Pic3Port setting Pic3Port setting Pic3Port setting Pic3Port setting Pic3
Port setting Pic4Port setting Pic4Port setting Pic4Port setting Pic4Port setting Pic4Port setting Pic4Port setting Pic4
SPI driver Config Pic1SPI driver Config Pic1SPI driver Config Pic1SPI driver Config Pic1SPI driver Config Pic1SPI driver Config Pic1SPI driver Config Pic1
SPI driver Config Pic2SPI driver Config Pic2SPI driver Config Pic2SPI driver Config Pic2SPI driver Config Pic2SPI driver Config Pic2SPI driver Config Pic2
SPI driver Config Pic3SPI driver Config Pic3SPI driver Config Pic3SPI driver Config Pic3SPI driver Config Pic3SPI driver Config Pic3SPI driver Config Pic3
SPI driver Config Pic4SPI driver Config Pic4SPI driver Config Pic4SPI driver Config Pic4SPI driver Config Pic4SPI driver Config Pic4SPI driver Config Pic4
SPI driver Config Pic5SPI driver Config Pic5SPI driver Config Pic5SPI driver Config Pic5SPI driver Config Pic5SPI driver Config Pic5SPI driver Config Pic5
SPI driver Config Pic6SPI driver Config Pic6SPI driver Config Pic6SPI driver Config Pic6SPI driver Config Pic6SPI driver Config Pic6SPI driver Config Pic6
Hi Robin,
Thank you for your response.
I have not installed the UJA116x example packages or referred to the example configurations that come with:
S32K1xx_SBC_UJA116xA_R21-11_0.8.0_CD01_DS_updatesite_D2401.zip
SW32K1_S32M24X_RTD_4.4_R21-11_2.0.0_D2308_DS_Updatesite.zip
Currently, I am using my own SPI implementation for communication with the UJA1169 SBC.
As requested, I have attached my test project separately for testing.
You can use it on the S32K144EVB-Q100 board and verify the SPI signals using a logic analyzer.
Please let me know if you need any additional information or modifications in the project.
Best Regards,
Vamshi
Hi
Could you please send me the test project separately for testing?
This way, I can use a logic analyzer on the S32K144EVB-Q100 to check if the SPI communication is correct.
By the way, I installed "S32K1xx_SBC_UJA116xA_R21-11_0.8.0_CD01_DS_updatesite_D2401.zip" and "SW32K1_S32M24X_RTD_4.4_R21-11_2.0.0_D2308_DS_Updatesite.zip" in S32DS v3.5. Did you also install this version?
After installation, there will be some UJA116x examples. Have you already referred to its configuration?
Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "ACCEPT AS SOLUTION" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
The definition in the red box below needs to be modified:
The following are the parts that need to be modified in the S32 Configuration Tool:
Please note that I only briefly checked and modified your project. I strongly recommend that you install S32K1xx_SBC_UJA116xA_R21-11_0.8.0_CD01_DS_updatesite_D2401.zip and refer to its example Sbc_uja116xa_example_S32K148.
I just installed S32K1 RTD 2.0.0 P04, and I can now correctly open your S32 Configuration Tool.
Sorry, I see you've defined Uja1169_Transfer, Uja1169_ReadDeviceId, etc.
However, I found more than one S32CT and Code error, and I haven't had time to fix them all yet.
I still recommend you install S32K1xx_SBC_UJA116xA_R21-11_0.8.0_CD01_DS_updatesite_D2401.zip and then use the official API, such as Sbc_43_uja116xa_ReadRegister(SBC_UJA116XA_IDENTIF, ReceivedData);
Hi Robin,
Thank you for your response.
I am unable to find the example project “Sbc_uja116xa_example_S32K148” and the related package “S32K1xx_SBC_UJA116xA_R21-11_0.8.0_CD01_DS_updatesite_D2401.zip” .
Could you please share the reference project and related files?
Thank you.
Best regards,
Vamshi