esp-32s1 reading RTC timer through ULP, getting garbage.

jshnaidm
Posts: 6
Joined: Mon Jul 05, 2021 3:47 am

esp-32s1 reading RTC timer through ULP, getting garbage.

Postby jshnaidm » Fri Jul 16, 2021 8:54 pm

  1. read_RTC_time:
  2.     WRITE_RTC_REG(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE_S, 1,1)
  3. wait_RTC_update:
  4.     READ_RTC_REG(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_VALID_S, 1)
  5.     jumpr wait_RTC_update, 0, eq
  6.     READ_RTC_REG(RTC_CNTL_TIME0_REG+2, 0, 16)
  7.     move r1, last_measurement_time
  8.     st r0, r1, 0
The value I'm getting in R0 looks pretty random. On the other hand, if I do:
  1. uint32_t* time0 = (uint32_t *) 0x3FF48010;
  2. printf("last_measurement_time: %X, current_time: %X\n", ulp_last_measurement_time & 0xFFFF, (*time0 & 0xFFFF0000) >> 16);
It seems like I can read the RTC timer fine from the main processor. Current_time makes sense, whereas ulp_last_measurement_time is garbage. What am I doing wrong?

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: esp-32s1 reading RTC timer through ULP, getting garbage.

Postby boarchuz » Sat Jul 17, 2021 4:45 am

READ_RTC_REG(RTC_CNTL_TIME0_REG+2, 0, 16)
This doesn't look right. Are you trying to read the upper 16 bits?: READ_RTC_REG(RTC_CNTL_TIME0_REG, 16, 16)

jshnaidm
Posts: 6
Joined: Mon Jul 05, 2021 3:47 am

Re: esp-32s1 reading RTC timer through ULP, getting garbage.

Postby jshnaidm » Sat Jul 17, 2021 5:20 am

boarchuz wrote:
Sat Jul 17, 2021 4:45 am
READ_RTC_REG(RTC_CNTL_TIME0_REG+2, 0, 16)
This doesn't look right. Are you trying to read the upper 16 bits?: READ_RTC_REG(RTC_CNTL_TIME0_REG, 16, 16)
Yeah! I got confused by the macro, I ended up just doing
  1. .set timer_top_16, (0x3FF48014 - DR_REG_RTCCNTL_BASE)/4
  2. REG_RD timer_top_16, 0, 16
And I got it working. Sorry for the trouble, and thank you. I see how what I was doing was wrong now.

Who is online

Users browsing this forum: earp123, Google [Bot] and 117 guests