Dear Mr. Earl,
I tried using the RTC to read the number of clock cycles. I used the RTC_TPR register. I Initialized the RTC and then read the value of the RTC_TPR register before loading the data variables and after loading the data variables.
I am trying to establish communication between an analog chip and the K53 microcontroller. I have done so using SPI link, but I want to confirm that the Analog chip (slave) is sending data at the rate I have asked it to. I have given a clock of 1000 kHz from the master for SPI communication, and I should be getting data at a rate of 2000 words per second from the slave. Now to achieve the timestamping, I have read the RTC clock at the event of receiving a word in the code. If the RTC clock is 32kHz, I should be able to correctly detect a data rate of 2000 words per second, right?
However, the time interval according to the RTC to get 500 data variables is much less than 0.25 seconds. It is around 0.0175 seconds.
Am I doing something wrong, either in using an RTC clock less than the SPI master clock (even though I need to detect the event as received word, not received byte), or in the way I am using the RTC clock?
The code I have used is below:
to initialize the RTC
void rtc_init(uint32 seconds, uint32 alarm, uint8 c_interval, uint8 c_value, uint8 interrupt)
{
int i;
/*enable the clock to SRTC module register space*/
SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;
/*Only VBAT_POR has an effect on the SRTC, RESET to the part does not, so you must manually reset the SRTC to make sure everything is in a known state*/
/*clear the software reset bit*/
RTC_CR = RTC_CR_SWR_MASK;
RTC_CR &= ~RTC_CR_SWR_MASK;
/*Enable the interrupt*/
if(interrupt)
enable_irq(66);
/*Enable the oscillator*/
RTC_CR |= RTC_CR_OSCE_MASK;
/*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/
for(i=0;i<0x600000;i++);
/*Set time compensation parameters*/
RTC_TCR = RTC_TCR_CIR(c_interval) | RTC_TCR_TCR(c_value);
/*Configure the timer seconds and alarm registers*/
RTC_TSR = seconds;
RTC_TAR = alarm;
RTC_TPR = 0;
/*Enable the counter*/
RTC_SR |= RTC_SR_TCE_MASK;
}
In main module, after SPI initialization:
time_initial= RTC_TPR;
time_initial_sec = RTC_TSR;
// test single byte transmission
while(j<500){
//for (j=0;j<4;j++){
for (i=0;i<=11;i++){
data[j] = reg_read(0x00000000);
//I2C0_D = data;
//I2C0_A1 = datain;
time = RTC_TPR;
time_sec = RTC_TSR;
// printf("dataout: %x\ndatain: %x\ntime: %x\nTimeDirect: %x\n\n",data,datain,*ticky,time);
j++;
// if(j==500)
// printf("500!\n");
}
//printf("%d\n",j);
reg_Write(0x40000000);
}
printf("initial time = %d\nintial sec = %d\nFinal Time =%d\nFinalTimeSec = %d\n\n",time_initial,time_initial_sec, time,time_sec);
}
Where reg_read and reg_Write are used to read and write from and to 32 bit words respectively.