SPI Communication on "s32k31XEVB-Q100 Evaluation Board" Hello, I have a s32k31XEVB-Q100 Evaluation Board and try to implement a SPI communication between the S32 and the FS23. My Pin-Configuration: PTB0 -> lpspi0_pcs0 PTC8 -> lpxpi0_sck PTC9 ->lpxpi0_sin PTB1 -> lpxpi0_sout In Peripherals I added Lpspi /* SPI */
/* Time to transfer all frame data */
#define BCC_MSG_SIZE 4U
#define RX_BUFFER_SIZE 4U
#define TIMEOUT ((uint32)1000000UL)
#define NUMBER_OF_BYTES (10)
uint16 numberOfBytes = BCC_MSG_SIZE;
static void handleSPI(void)
{
static int counterSPI = 0;
__attribute__(( aligned(32) )) uint8_t rxBuffer[BCC_MSG_SIZE] = {0x00};// = {0,0,0,0,0,0,0,0,0,0,0,0}; /* Buffer for receiving. */
__attribute__(( aligned(32) )) uint8_t txBuffer[BCC_MSG_SIZE] = {0x00}; /* Transmission buffer. */
/* M_DEV_PROG_ID
*
*/
txBuffer[0] = 0x01 << 1; // General status flags ( Register address / Read/Write)
txBuffer[1] = 0x00; // Read Data
txBuffer[2] = 0x00; // Read Data
txBuffer[3] = 0x00; // CRC
if (counterSPI++ >= 5000000)
{
counterSPI = 0;
lpspi_status = Lpspi_Ip_SyncTransmit(&MASTER_EXTERNAL_DEVICE, &txBuffer[0], &rxBuffer[0], numberOfBytes, 100000);
}
}
int main(void)
{
/* Write your code here */
Clock_Ip_StatusType clockStatus;
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);
FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0);
FlexCAN_Ip_SetRxIndividualMask(INST_FLEXCAN_0,RX_MB_IDX,0xFFFFFFFF);
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX, &rx_info, Rx_MSG_ID);
FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);
//FlexCAN_Ip_Receive(INST_FLEXCAN_0,RX_MB_IDX,&rxData,false);
lpspi_status = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_0_Instance_0);
/* update Transfer Mode */
//Lpspi_Ip_UpdateTransferMode(MASTER_EXTERNAL_DEVICE.Instance, LPSPI_IP_INTERRUPT);
for(;;)
{
handleSPI();
handleCAN();
handleLED();
if(exit_code != 0)
{
break;
}
}
return exit_code;
} Now I connected my Logic-Analyzer to J39 on the Board. The result of this code is: Now I have some questions: 1) Do I send the values in the right order? 2) Do I have to send the CRC when I just want to read some Data? 3) Which register of the FS23 on this board returns fixed data? Or data which I could know to verify the answer? 4) in the CLK I see sometimes that the clk is longer than normal. Do you have some hints to get the SPI-Communication working for me? Re: SPI Communication on "s32k31XEVB-Q100 Evaluation Board" Hi John
Please see comment below:
Here I only support FS23 not the S32K so I will reply to you from the view point of FS23.
Now I have some questions:
1) Do I send the values in the right order?
[gw]Please see answer2 for more detail format about read and write operations.
Please also read AN12149 page16--5 MCU communication for getting more info about READ/WRITE/CRC
2) Do I have to send the CRC when I just want to read some Data?
[gw]Yes,The SPI communication frame format is as follows: CRC is present by default and cannot be disabled. During read and write operations, the MSB is transmitted first and the LSB last. When SPI is idle, i.e., when the CSB pin is high, MISO is in a high-impedance state.
In the AN14129 Page11 page16 introduce the INIT CRC and normal CRC calculation methods.
They are different.
3) Which register of the FS23 on this board returns fixed data? Or data which I could know to verify the answer?
[gw] M_DEV_PROG_ID address is 0x01 4) in the CLK I see sometimes that the clk is longer than normal.
[gw]You test waveform when CS change to low the CLCK is high but in our timing diagram it's low.
View full article