SPI read is not working with default driver.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

SPI read is not working with default driver.

ソリューションへジャンプ
1,333件の閲覧回数
kishoresamy
Contributor I

Hi,

 

I have created the project for kl46z. I have used processor expert in codewarrior.

There i have enabled SPI component with interrupt method

So the library created with the name called SM1.c, now the interrupt function (ISR) default

created like this :

 

PE_ISR(SM1_Interrupt)

{

  /* {FreeRTOS RTOS Adapter} ISR parameter is passed through the global variable */

  SM1_TDeviceDataPtr DeviceDataPrv = INT_SPI0__BAREBOARD_RTOS_ISRPARAM;

  uint8_t StatReg = SPI_PDD_ReadStatusReg(SPI0_BASE_PTR); /* Read status register */

 

 

  (void)DeviceDataPrv;                 /* Supress unused variable warning if needed */

  if ((StatReg & SPI_PDD_RX_BUFFER_FULL) != 0U) { /* Is any char in HW Rx buffer? */

    if (DeviceDataPrv->InpDataNumReq != 0x00U) { /* Is the receive block operation pending? */

      *(DeviceDataPrv->InpDataPtr++) = SPI_PDD_ReadData8bit(SPI0_BASE_PTR); /* Put a character to the receive buffer and increment pointer to receive buffer */

      DeviceDataPrv->InpRecvDataNum++; /* Increment received char. counter */

      if (DeviceDataPrv->InpRecvDataNum == DeviceDataPrv->InpDataNumReq) { /* Is the requested number of characters received? */

        SPI_PDD_DisableInterruptMask(SPI0_BASE_PTR, SPI_PDD_RX_BUFFER_FULL_OR_FAULT); /* Disable Rx buffer full interrupt */

        DeviceDataPrv->InpDataNumReq = 0x00U; /* If yes then clear number of requested characters to be received. */

        SM1_OnBlockReceived(DeviceDataPrv->UserData);

      }

    }

  }

  if ((StatReg & SPI_PDD_TX_BUFFER_EMPTYG) != 0U) { /* Is HW Tx buffer empty? */

    if (DeviceDataPrv->OutSentDataNum < DeviceDataPrv->OutDataNumReq) { /* Is number of sent characters less than the number of requested incoming characters? */

      SPI_PDD_WriteData8Bit(SPI0_BASE_PTR, (*((uint8_t *)DeviceDataPrv->OutDataPtr++))); /* Put a character with command to the transmit register and increment pointer to the transmitt buffer */

      DeviceDataPrv->OutSentDataNum++; /* Increment the counter of sent characters. */

      if (DeviceDataPrv->OutSentDataNum == DeviceDataPrv->OutDataNumReq) {

        DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of characters to be send by SendBlock() */

        SM1_OnBlockSent(DeviceDataPrv->UserData);

      }

    } else {

      SPI_PDD_DisableInterruptMask(SPI0_BASE_PTR, SPI_PDD_TX_BUFFER_EMPTY); /* Disable TX interrupt */

    }

  }

}

 

 

But with this code SPI read function is not working. But i made it working with including two lines

in PE_ISR(SM1_Interrupt). i copied here my changes

 

included two lines are highlighted with BOLD letter down:

PE_ISR(SM1_Interrupt)

{

  /* {FreeRTOS RTOS Adapter} ISR parameter is passed through the global variable */

  SM1_TDeviceDataPtr DeviceDataPrv = INT_SPI0__BAREBOARD_RTOS_ISRPARAM;

  uint8_t StatReg = SPI_PDD_ReadStatusReg(SPI0_BASE_PTR); /* Read status register */

 

 

  (void)DeviceDataPrv;                 /* Supress unused variable warning if needed */

  if (DeviceDataPrv->OutDataNumReq == 0x00U)

  if ((StatReg & SPI_PDD_RX_BUFFER_FULL) != 0U) { /* Is any char in HW Rx buffer? */

    if (DeviceDataPrv->InpDataNumReq != 0x00U) { /* Is the receive block operation pending? */

      *(DeviceDataPrv->InpDataPtr++) = SPI_PDD_ReadData8bit(SPI0_BASE_PTR); /* Put a character to the receive buffer and increment pointer to receive buffer */

     SPI_PDD_WriteData8Bit(SPI0_BASE_PTR, 0);

      DeviceDataPrv->InpRecvDataNum++; /* Increment received char. counter */

      if (DeviceDataPrv->InpRecvDataNum == DeviceDataPrv->InpDataNumReq) { /* Is the requested number of characters received? */

        SPI_PDD_DisableInterruptMask(SPI0_BASE_PTR, SPI_PDD_RX_BUFFER_FULL_OR_FAULT); /* Disable Rx buffer full interrupt */

        DeviceDataPrv->InpDataNumReq = 0x00U; /* If yes then clear number of requested characters to be received. */

        SM1_OnBlockReceived(DeviceDataPrv->UserData);

      }

    }

  }

  if ((StatReg & SPI_PDD_TX_BUFFER_EMPTYG) != 0U) { /* Is HW Tx buffer empty? */

    if (DeviceDataPrv->OutSentDataNum < DeviceDataPrv->OutDataNumReq) { /* Is number of sent characters less than the number of requested incoming characters? */

      SPI_PDD_WriteData8Bit(SPI0_BASE_PTR, (*((uint8_t *)DeviceDataPrv->OutDataPtr++))); /* Put a character with command to the transmit register and increment pointer to the transmitt buffer */

      DeviceDataPrv->OutSentDataNum++; /* Increment the counter of sent characters. */

      if (DeviceDataPrv->OutSentDataNum == DeviceDataPrv->OutDataNumReq) {

        DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of characters to be send by SendBlock() */

        SM1_OnBlockSent(DeviceDataPrv->UserData);

      }

    } else {

      SPI_PDD_DisableInterruptMask(SPI0_BASE_PTR, SPI_PDD_TX_BUFFER_EMPTY); /* Disable TX interrupt */

    }

  }

}

 

 

Now all working fine. But whenever i do clear and build for my project, all generated files created with

default code. so my changes also got erased. I want that two line to be there always even if

do clear and build. Basically default SPI driver function PE_ISR(SM1_Interrupt) is not working

for me. so i changed that function so that i am able to communicate over the SPI. how to

stop regenerating SM1.c when i do clear and build?

ラベル(1)
0 件の賞賛
返信
1 解決策
985件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello kishore,

After you finish changing the code , please select the "Don't writhe generated component modules":

pastedImage_0.png

then when you build the code, it will not  changed , and also when you re change the configuration

of the SPI component , please select the "Always write.." option , or it also can not change the code .

Hope it helps


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
986件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello kishore,

After you finish changing the code , please select the "Don't writhe generated component modules":

pastedImage_0.png

then when you build the code, it will not  changed , and also when you re change the configuration

of the SPI component , please select the "Always write.." option , or it also can not change the code .

Hope it helps


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
985件の閲覧回数
kishoresamy
Contributor I

Hello Alice,

Thank you so much. my issue solved after following your instruction.

Thanks & Rgds,

Kishore R.

0 件の賞賛
返信
985件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Kishore,

Welcome !

If the answer is right , It will be very nice you click the "Mark Correct" , then are people can refer to .

BR

Alice

0 件の賞賛
返信