S32K311 SPI Issues Hello, I am using a s32k31XEVB-Q100 and have some troubles to get the SPI Communication between the S32K311 and the FS23. I use the Lpspi and the Sbc_fs23_Ip driver in Non-Autosar. The SPI itself is working, but I have some trouble with the Sbc_fs23_Ip. int main(void)
{
/* Write your code here */
Clock_Ip_StatusType clockStatus;
volatile Sbc_fs23_Ip_StatusType sbcStatus;
Std_ReturnType eReturnValue = E_NOT_OK;
clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);
if (CLOCK_IP_SUCCESS != clockStatus)
{
exit_code = -1;
}
/* Initial Pins */
Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);
/* Initial ISR */
IntCtrl_Ip_Init(&IntCtrlConfig_0);
IntCtrl_Ip_EnableIrq(FlexCAN0_0_IRQn);
/* already enabled in IntCtrl_Ip - Interrupt Controller */
//IntCtrl_Ip_EnableIrq(FlexCAN0_1_IRQn);
//IntCtrl_Ip_EnableIrq(FlexCAN0_2_IRQn);
//IntCtrl_Ip_EnableIrq(FlexCAN0_2_IRQn);
OsIf_Init(NULL_PTR);
// FlexCAN Init
FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0);
FlexCAN_Ip_SetRxIndividualMask(INST_FLEXCAN_0,CAN_RX_MB_IDX,0xFFFFFFFF);
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, CAN_RX_MB_IDX, &CAN_rx_info, CAN_Rx_MSG_ID);
FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);
//FlexCAN_Ip_Receive(INST_FLEXCAN_0,CAN_RX_MB_IDX,&rxData,false);
// LPSPI Init
lpspi_status = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_0_Instance_0);
uint8 y = 0;
for (uint8 x=0; x<50; x++)
{
txTestSpiBuffer[0] = y++;
txTestSpiBuffer[1] = y++;
txTestSpiBuffer[2] = y++;
txTestSpiBuffer[3] = y++;
//lpspi_status = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, txBuffer, rxBuffer, NUMBER_OF_BYTES, TIMEOUT);
lpspi_status = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, txTestSpiBuffer, rxTestSpiBuffer, 4, ((uint32)1000000UL));
}
/* Initialize Sbc driver */
Sbc_fs23_Ip_InitDriver(&Sbc_fs23_Ip_Config);
/* Call function Sbc_fs23_GoToInitState to put device into INIT state*/
eReturnValue = Sbc_fs23_Ip_GoToInitState(SBC_FS23_DEVICE_ID);
y = 0;
for (uint8 x=0; x<50; x++)
{
txTestSpiBuffer[0] = y++;
txTestSpiBuffer[1] = y++;
txTestSpiBuffer[2] = y++;
txTestSpiBuffer[3] = y++;
//lpspi_status = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, txBuffer, rxBuffer, NUMBER_OF_BYTES, TIMEOUT);
lpspi_status = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, txTestSpiBuffer, rxTestSpiBuffer, 4, ((uint32)1000000UL));
} First I use Lpspi_Ip_SyncTransmit from Lpspi-Driver directly. This is just to see that the SPI in generel is working. Then I use the Sbc_fs23_Ip driver. Here I have some issues with the SPI. Because I thought maybe something is reconfigured in the Sbc_fs23_Ip driver I use the Lpspi_Ip_SyncTransmit from Lpspi-Driver directly again. In the Fisrt loop where I use the Lpspi-Driver directly the communication looks good. Then the function Sbc_fs23_Ip_GoToInitState is called. There also multiple commands are send via SPI, but the it looks like the Datas are not send correctly After that I used the Lpspi_Ip_SyncTransmit directly again and the communication looks good again. In Lpspi_Ip.c I can wait until the TCF Flag from LPSPI0 is set to send the next data. This works, but shouldn't be the solution. LOCAL_INLINE void Lpspi_Ip_PushDataToFifo(uint8 Instance,
uint8 NumberOfWrites)
{
LPSPI_Type* Base = Lpspi_Ip_apxBases[Instance];
Lpspi_Ip_StateStructureType* State = Lpspi_Ip_apxStateStructureArray[Instance];
uint32 Data = 0u;
uint8 Index = 0u;
/* Default data will be sent if TX buffer is null */
Data = State->ExternalDevice->DeviceParams->DefaultData;
/* To increase the performance of transfer, we will reduce the checking conditions in per "for" statement so we should have more than 1 "for"
* statement here */
if (NULL_PTR != State->TxBuffer)
{
if (State->ExternalDevice->DeviceParams->FrameSize < 9u)
{
for (Index = 0; Index < NumberOfWrites; Index++)
{
Data = *((const uint8*)(&State->TxBuffer[State->TxIndex + Index]));
Base->TDR = Data;
}
}
else if (State->ExternalDevice->DeviceParams->FrameSize < 17u)
{
for (Index = 0; Index < NumberOfWrites; Index++)
{
Data = *((const uint16*)(&State->TxBuffer[2u * (State->TxIndex + Index)]));
Base->TDR = Data;
}
}
else
{
for (Index = 0; Index < NumberOfWrites; Index++)
{
Data = *((const uint32*)(&State->TxBuffer[4u * (State->TxIndex + Index)]));
Base->TDR = Data;
while ((Base->SR & LPSPI_SR_TCF_MASK) == 0U)
{
/* NEW, WAIT TILL TCF FLAG IS SET */
}
}
}
}
else
{
for (Index = 0; Index < NumberOfWrites; Index++)
{
Base->TDR = Data;
}
}
State->TxIndex += NumberOfWrites;
} What I also see is that the Datas are in the wrong order. When calling Sbc_fs23_Ip_GoToInitState the first command is to read the SBC_FS23_IP_M_STATUS_ADDR (0x03) So the 0x06 should at the beginning of the Transmitted Datas? Do you have an Idea what could be wrong? I have been having these problems for several days now and am unable to make any progress. Re: S32K311 SPI Issues Hi
As an initial guess, the SPI configuration or data packing may be incorrect. The bytes appear to be swapped during the generic SPI transfer, which can happen when using a 32-bit SPI frame with byte-oriented buffers and byte swapping disabled. Also, using the same PCS for a generic SPI test is not ideal while the SBC is connected, because the SBC will also receive those test frames. Please use a separate PCS or disconnect/disable the SBC during a generic LPSPI test.
The attached main.c confirms that the project is based on S32K3 RTD 7.0.1, build S32K3_RTD_7_0_1_D2602_ASR_REL_4_9_REV_0000_20260206 . It includes and uses Sbc_fs23_Ip , but the exact FS23 SBC driver package version cannot be determined from the source file. The attached Blink.mex also identifies the SBC component but does not contain its package release.
For comparison, the latest FS23 SBC driver 2.0.0 is used with S32K3 RTD 7.0.1, and the available S32K312 FS23 demo uses different SPI settings, including 8-bit transfers and chip select kept asserted. I recommend comparing your configuration with the available FS23 demo, especially the SPI data width, chip-select behavior, and transfer sequence.
BR, Petr
View full article