Hello Nxp,
I am writing to you regarding a problem I have with the RTC chip PCA21125 communication with Aurix Microcontroller Tc389. I am unable to write the RTC registers, which prevents me from clearing the POR bit of Control 1 register and the RF bit of Second register. As a result, the SECONDS bitfield of Second register is not incrementing.
I am sharing my code.I would appreciate it if you could review it and give me your feedback. Is there anything I am missing or doing wrong? I have posted this question on the community forum before, but I did not receive any reply.
Control_1 register Init Code :
FUNC(CDD_RTC_PCA_StatusType, CDD_RTC_PCA) CDD_RTC_PCA_RegCtrl1Init(void)
{
VAR(uint16, AUTOMATIC) DataIndex = 0U;
VAR(Std_ReturnType, TYPEDEF) RetVal = E_OK;
VAR(CDD_RTC_PCA_StatusType, TYPEDEF) eRTC_Status = CDD_RTC_OK;
PCAReg.RegCntrl_1.uint8_reg = RTC_REGCTRL1_INTI_VAL;
Cdd_RTC_SPITxBuff[DataIndex++] = WRITE_CMD | RTC_REG_CONTROL_1;
Cdd_RTC_SPITxBuff[DataIndex++] = PCAReg.RegCntrl_1.uint8_reg;
RetVal |= Spi_SetupEB(CDD_RTC_PCA_SPI_CHNL, &Cdd_RTC_SPITxBuff[0U], &Cdd_RTC_SPIRxBuff[0U], DataIndex);
/* Send data filled in SPI buffer over SPI */
RetVal |= CDD_RTC_SpiSend();
/* Check if SPI transfer successful */
if(E_OK != RetVal)
{
eRTC_Status = CDD_RTC_SPI_FAILURE;
}
else
{
// do nothing
}
return eRTC_Status;
}
Control_2 Register Init Code
FUNC(CDD_RTC_PCA_StatusType, CDD_RTC_PCA) CDD_RTC_PCA_RegCtrl2Init(void)
{
VAR(uint16, AUTOMATIC) DataIndex = 0U;
VAR(Std_ReturnType, TYPEDEF) RetVal = E_OK;
VAR(CDD_RTC_PCA_StatusType, TYPEDEF) eRTC_Status = CDD_RTC_OK;
PCAReg.RegCntrl_2.uint8_reg = RTC_REGCTRL2_INTI_VAL;
Cdd_RTC_SPITxBuff[DataIndex++] = WRITE_CMD | RTC_REG_CONTROL_2;
Cdd_RTC_SPITxBuff[DataIndex++] = PCAReg.RegCntrl_2.uint8_reg;
RetVal |= Spi_SetupEB(CDD_RTC_PCA_SPI_CHNL, &Cdd_RTC_SPITxBuff[0U], &Cdd_RTC_SPIRxBuff[0U], DataIndex);
/* Send data filled in SPI buffer over SPI */
RetVal |= CDD_RTC_SpiSend();
/* Check if SPI transfer successful */
if(E_OK != RetVal)
{
eRTC_Status = CDD_RTC_SPI_FAILURE;
}
else{
//do nothing
}
return eRTC_Status;
}
Clear RF bit Function :
FUNC(CDD_RTC_PCA_StatusType, CDD_RTC_PCA) CDD_RTC_PCA_DriverInit(void)
{
VAR(Std_ReturnType, TYPEDEF) RetVal = E_OK;
VAR(CDD_RTC_PCA_StatusType, TYPEDEF) eRTC_Status = CDD_RTC_OK;
/* Set SPI to Sync Mode for Driver initialization */
u8RTC_SPIMode = CDD_RTC_PCA_SYNC_MODE;
RetVal |= CDD_RTC_PCA_RegCtrl1Init();
RetVal |= CDD_RTC_PCA_RegCtrl2Init();
RetVal |= CDD_RTC_PCA_CLearRF();
if(E_OK == RetVal)
{
eRTC_Status = CDD_RTC_OK;
/* Initialize RTC state to Idle */
u8RTCState = RTC_IDLE_STATE;
u8RTC_SPIMode = CDD_RTC_SPI_MODE_CFG;
}
else
{
eRTC_Status = E_NOT_OK;
}
return eRTC_Status;
}
Read Register Code :
FUNC(CDD_RTC_PCA_StatusType, CDD_RTC_PCA) CDD_RTC_PCA_ReadReg( VAR(uint8, AUTOMATIC) u8StartIndx,
VAR(uint8, AUTOMATIC) u8TotalRegToRead,
P2VAR(uint8, AUTOMATIC, CDD_RTC_PCA) DataPtr )
{
VAR(uint8, AUTOMATIC) u8LoopIndx = 0U;
VAR(uint16, AUTOMATIC) DataIndex = 0U;
VAR(Std_ReturnType, TYPEDEF) RetVal = E_OK;
VAR(CDD_RTC_PCA_StatusType, TYPEDEF) eRTC_Status = CDD_RTC_OK;
g_TotalRegToRead = u8TotalRegToRead;
Cdd_RTC_SPITxBuff[DataIndex++] = READ_CMD | u8StartIndx;
for(u8LoopIndx = 0U; u8LoopIndx < u8TotalRegToRead; u8LoopIndx++)
{
Cdd_RTC_SPITxBuff[DataIndex++] = u8StartIndx + u8LoopIndx;
}
RetVal |= Spi_SetupEB(CDD_RTC_PCA_SPI_CHNL, &Cdd_RTC_SPITxBuff[0U], &Cdd_RTC_SPIRxBuff[0U], DataIndex);
/* Send data filled in SPI buffer over SPI */
RetVal |= CDD_RTC_SpiSend();
/* Check if SPI transfer successful */
if(E_OK != RetVal)
{
eRTC_Status = CDD_RTC_SPI_FAILURE;
}
else
{ //do nothing }
return eRTC_Status;
}
SPI Configuration :
Chip Select polarity : High
Data Shifting edge : Trailing
Channel configuration --> Data Width : 8
I have been struggling over this for long time , please give the necessity inputs.
Hello AshBirari,
I hope all is great with you. Thank you for using the NXP communities.
As we know, the first byte transmitted is the command byte. Are you following the correct procedure for the first byte?
Could you please share an oscilloscope trace of your writing procedure?
Regards,
David
Hello David,
I had tried to upload the images through the drag-drop tool but it gives me notification that " You do not have permission to upload the images."
So I request you to please share an mail id on which I can attach my oscilloscope snippets.
Hello,
In this case, I do recommend to submit a new case to get assistance from our team.
Regards,
David
Hello David,
Yes , I am transmitting First byte as Command byte as you can see the above code.
I have tried to upload oscilloscope images but failed . Can you provide mail id where I can attach the results of oscilloscope ?