AnsweredAssumed Answered

Why SPI slave's output is shifted to the left?

Question asked by Kim JungHyun on Jul 10, 2017
Latest reply on Jul 14, 2017 by Raymundo Velarde

Hi. I have to change some parts of my question.

I found SPI's slave output was as below.

■ SPI's slave output is shifted to the left 

   - with 1 clock(1bit)

   - only one time

   - whenever SPI starts first in interrupt

   - 1 is added to the last bit (farthest to the right )

   - from second frame, all frames are not shifted (1 frame is 8byte)

ex) original frame(8byte) : 0x01..., 0x82

      shifted frame(8byte) : 0x02..., 0x05

■ I have to send 0x01..., 0x82 first. How could I do it?

   * Current problem is 'SPI's slave output is shifted to the left' but my goal is to send 0x01..., 0x82.

     so I changed the frame value to '0x00, 0x80... 0x41'. (this value will be shifted and changed to '0x01..., 0x82')

     But I missed that 1 is added to the last bit and the frame value became  0x01..., 0x83. I could not make it.

---------------------------------------------------------------------------------------------------------------------------------------------------

 

Hi.

I am confused because SPI slave's output is shifted to the left.

SPI slave's output is 0x01 but it is changed to 0x02 when I changed some source code.

The code's difference is only whether 'LPSPI_DRV_SlaveTransfer()' is in if() or not

I hope somebody helps me.

 

<0x01 output>

#define BUFFER_SIZE 8U
uint8_t slaveDataReceive_1[8] = {0x00};
uint8_t slaveDataSend_1_1[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0xfd,0x82};

...

void PORTB_ISR(void)
{
  PORT_HAL_ClearPortIntFlagCmd(PORTB);
  LPSPI_DRV_SlaveTransfer(RECEIVE,&slaveDataSend_1_1,slaveDataReceive_1,BUFFER_SIZE);
...
}

 

<0x02 output>

#define BUFFER_SIZE 8U
uint8_t slaveDataReceive_1[8] = {0x00};
uint8_t slaveDataSend_1_1[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0xfd,0x82};

...

void PORTB_ISR(void)
{
  PORT_HAL_ClearPortIntFlagCmd(PORTB);
  if(c1==1){
      c1=0;
      LPSPI_DRV_SlaveTransfer(RECEIVE,&slaveDataSend_1_3,slaveDataReceive_1,BUFFER_SIZE);
      d1=1;
   }
   if(b1==1){
    b1=0;
    LPSPI_DRV_SlaveTransfer(RECEIVE,&slaveDataSend_1_2,slaveDataReceive_1,BUFFER_SIZE);
    c1=1;
   }
   if(a1==1){
    a1=0;
    LPSPI_DRV_SlaveTransfer(RECEIVE,&slaveDataSend_1_1,slaveDataReceive_1,BUFFER_SIZE);
    b1=1;
   }
...
}

Outcomes