AnsweredAssumed Answered

S32K 144 spi send 8 bytes msg issue

Question asked by Terry Liu on Apr 8, 2019
Latest reply on Oct 24, 2019 by wang aoyuan

Dear supports:

  I need spi send msg like follow picture, but I found spi only send up to 32 bits.

 

This is the code:

void LPSPI0_init_master(void) {

  PCC->PCCn[PCC_LPSPI0_INDEX] = 0;          /* Disable clocks to modify PCS ( default) */
  PCC->PCCn[PCC_LPSPI0_INDEX] = 0xC6000000; /* Enable PCS=SPLL_DIV2 (40 MHz func'l clock) */
  
  LPSPI0->CR    = 0x00000000;   /* Disable module for configuration */
  LPSPI0->IER   = 0x00000000;   /* Interrupts not used */
  LPSPI0->DER   = 0x00000000;   /* DMA not used */
  LPSPI0->CFGR0 = 0x00000000;   /* Defaults: */
                                /* RDM0=0: rec'd data to FIFO as normal */
                                /* CIRFIFO=0; Circular FIFO is disabled */
                                /* HRSEL, HRPOL, HREN=0: Host request disabled */
  LPSPI0->CFGR1 = 0x08000001;   /* Configurations: master mode*/
                                /* PCSCFG=0: PCS[3:2] are enabled */
                                /* OUTCFG=0: Output data retains last value when CS negated */
                                /* PINCFG=0: SIN is input, SOUT is output */
                                /* MATCFG=0: Match disabled */
                                /* PCSPOL=0: PCS is active low */
                                /* NOSTALL=0: Stall if Tx FIFO empty or Rx FIFO full */
                                /* AUTOPCS=0: does not apply for master mode */
                                /* SAMPLE=0: input data sampled on SCK edge */
                                /* MASTER=1: Master mode */
  LPSPI0->TCR   = 0x5900000f;   /* Transmit cmd: PCS1, 8 bits, prescale func'l clk by 8, etc*/
                                /* CPOL=0: SCK inactive state is low */
                                /* CPHA=1: Change data on SCK lead'g, capture on trail'g edge*/
                                /* PRESCALE=4: Functional clock divided by 8 */
                                /* PCS=1: Transfer using PCS1 */
                                /* LSBF=0: Data is transfered MSB first */
                                /* BYSW=0: Byte swap disabled */
                                /* CONT, CONTC=0: Continuous transfer disabled */
                                /* RXMSK=0: Normal transfer: rx data stored in rx FIFO */
                                /* TXMSK=0: Normal transfer: data loaded from tx FIFO */
                                /* WIDTH=0: Single bit transfer */
                                /* FRAMESZ=63: # bits in frame = 63+1=64 */
  LPSPI0->CCR   = 0x04090808;   /* Clock dividers based on prescaled func'l clk of 100 nsec */
                                /* SCKPCS=4: SCK to PCS delay = 4+1 = 5 (500 nsec) */
                                /* PCSSCK=4: PCS to SCK delay = 9+1 = 10 (1 usec) */
                                /* DBT=8: Delay between Transfers = 8+2 = 10 (1 usec) */
                                /* SCKDIV=8: SCK divider =8+2 = 10 (1 usec: 1 MHz baud rate) */
  LPSPI0->FCR   = 0x00000003;   /* RXWATER=0: Rx flags set when Rx FIFO >0 */
                                /* TXWATER=3: Tx flags set when Tx FIFO <= 3 */
  LPSPI0->CR    = 0x00000009;   /* Enable module for operation */
                                /* DBGEN=1: module enabled in debug mode */
                                /* DOZEN=0: module enabled in Doze mode */
                                /* RST=0: Master logic not reset */
                                /* MEN=1: Module is enabled */
}
void LPSPI0_transmit_16bits (uint16_t send) {
  while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
                                   /* Wait for Tx FIFO available */
  LPSPI0->TDR = send;              /* Transmit data */
  //LPSPI0->TDR = send2;              /* Transmit data */
  LPSPI0->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */
}
uint16_t LPSPI0_receive_16bits (void) {
  uint16_t recieve = 0;
  while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
                                   /* Wait at least one RxFIFO entry */
  recieve= LPSPI0->RDR;            /* Read received data */
  LPSPI0->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
  return recieve;                  /* Return received data */
}
 Function called LPSPI0_transmit_16bits() cyclic.
 If I try set LPSPI0->TCR  to  0x5900001f(FRAMESZ = 31), It seems ok. I can see any wave form  on the Oscilloscope.
 If I try set LPSPI0->TCR  to  0x5900003f(FRAMESZ = 63), It seems failed. I can't see any wave form  on the Oscilloscope.
Could you give me some help? Thanks in advance!

Outcomes