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?
Solved! Go to Solution.
Hello kishore,
After you finish changing the code , please select the "Don't writhe generated component modules":
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!
-----------------------------------------------------------------------------------------------------------------------
Hello kishore,
After you finish changing the code , please select the "Don't writhe generated component modules":
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!
-----------------------------------------------------------------------------------------------------------------------
Hello Alice,
Thank you so much. my issue solved after following your instruction.
Thanks & Rgds,
Kishore R.
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