PCA21125 RTC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PCA21125 RTC

411 Views
AshBirari
Contributor I

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_CLearRF(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.RegSeconds.bit.RF = CDD_RTC_RF_CLR;
 
    Cdd_RTC_SPITxBuff[DataIndex++]   = WRITE_CMD | RTC_REG_SECONDS;
    Cdd_RTC_SPITxBuff[DataIndex++]   = PCAReg.RegSeconds.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{
 
}
RTC Driver Init Code

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.

0 Kudos
8 Replies

383 Views
AshBirari
Contributor I

Hello NXP, Please give me a reply

0 Kudos

378 Views
diazmarin09
NXP TechSupport
NXP TechSupport

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?

diazmarin09_0-1702940407245.png

 

Could you please share an oscilloscope trace of your writing procedure?

 

diazmarin09_1-1702940434331.png

 

Regards,

David

0 Kudos

366 Views
AshBirari
Contributor I

Hello David,

I have shared image of Oscilloscope via mail , which represents write operation on Control Register 1.

Violet : SDI Line of PCA21125 RTC chip.

Yellow : Clock

0 Kudos

361 Views
diazmarin09
NXP TechSupport
NXP TechSupport

Hello AshBirari,

Could you please try to attach the file using the tool below? 

diazmarin09_0-1703006224687.png

Regards,

David 

 

0 Kudos

355 Views
AshBirari
Contributor I

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.

0 Kudos

352 Views
diazmarin09
NXP TechSupport
NXP TechSupport

Hello,

In this case, I do recommend to submit a new case to get assistance from our team. 

Regards,

David 

0 Kudos

335 Views
AshBirari
Contributor I
Link you have provided to me is not working either.

Regards,
AshBirari
0 Kudos

368 Views
AshBirari
Contributor I

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 ? 

0 Kudos