proper register set up for ULP I2C read or write?

pwiner99
Posts: 8
Joined: Tue Jun 05, 2018 1:51 pm

proper register set up for ULP I2C read or write?

Postby pwiner99 » Wed Jun 06, 2018 2:09 pm

My i2c read seems to block / stall my ULP code. I am using legacy macros, and needed to write the macro for the read and write instruction - which I posted to another thread. But not sure why it stalls. Also no indication of pin activity on SCL. Here is my register setup. Note: I tried using rtc_gpio_init - which sets bit 19 , or the two lines under to (commented out) to clear the bit in the RTC_IO_TOUCH_PADx register. Neither approach was successful. Printf's are for debug. Comment out the i2c_rd and everything runs as expected.

// Set up as many registers we can for i2c operation

// Set the pin mux to put SCL on pin 22 (GPIO2, RTC_GPIO12, Touch 2)
// Set the pin mux to put SDA on pin 23 (GPIO3, RTC_GPIO11, Touch 1)
WRITE_PERI_REG(RTC_IO_SAR_I2C_IO_REG,0x10000000); //basically set bit 28 everything else 0
printf("RTC_TO_SAR_I2D_IO_REG: 0x%x\n",READ_PERI_REG(RTC_IO_SAR_I2C_IO_REG));

//try using the esp-idf macro, it seems to set the bits, oposite of what I did below
rtc_gpio_init(GPIO_NUM_0);
rtc_gpio_init(GPIO_NUM_2);
//clear the mux bit in the touch pad register, this should route the signals to the RTC module?
//CLEAR_PERI_REG_MASK(RTC_IO_TOUCH_PAD1_REG,RTC_IO_TOUCH_PAD1_MUX_SEL_M);
//CLEAR_PERI_REG_MASK(RTC_IO_TOUCH_PAD2_REG,RTC_IO_TOUCH_PAD2_MUX_SEL_M);
printf("RTC_IO_TOUCH_PAD1_REG: 0x%x\n",READ_PERI_REG(RTC_IO_TOUCH_PAD1_REG));
printf("RTC_IO_TOUCH_PAD2_REG: 0x%x\n",READ_PERI_REG(RTC_IO_TOUCH_PAD2_REG));

//set up registers as suggested in the tech spec for 100Khz operation
WRITE_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG,40); //low half period in rtc_fast_clk cycles
WRITE_PERI_REG(RTC_I2C_SCL_HIGH_PERIOD_REG,40); //high half periond in rtc_fast_clk cycles
WRITE_PERI_REG(RTC_I2C_SDA_DUTY_REG,16); //SDA to SCL delay in rtc_fast_clk cycle
WRITE_PERI_REG(RTC_I2C_SCL_START_PERIOD_REG,30); //wait time after start
WRITE_PERI_REG(RTC_I2C_SCL_STOP_PERIOD_REG,44); //wait time befor end
WRITE_PERI_REG(RTC_I2C_TIMEOUT_REG,200); //transaction timeout
SET_PERI_REG_MASK(RTC_I2C_CTRL_REG,RTC_I2C_MS_MODE_M); //set to master mode
SET_PERI_REG_BITS(SENS_SAR_SLAVE_ADDR1_REG,SENS_I2C_SLAVE_ADDR0,LIS3DH_SLAVE_0,SENS_I2C_SLAVE_ADDR0_S); //address0 is 0x18

printf("RTC_I2C_SCL_LOW_PERIOD_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG));
printf("RTC_I2C_SCL_HIGH_PERIOD_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_SCL_HIGH_PERIOD_REG));
printf("RTC_I2C_SDA_DUTY_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_SDA_DUTY_REG));
printf("RTC_I2C_SCL_START_PERIOD_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_SCL_START_PERIOD_REG));
printf("RTC_I2C_SCL_STOP_PERIOD_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_SCL_STOP_PERIOD_REG));
printf("RTC_I2C_TIMEOUT_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_TIMEOUT_REG));
printf("RTC_I2C_CTRL_REG: 0x%x\n",READ_PERI_REG(RTC_I2C_CTRL_REG));
printf("SENS_SAR_SLAVE_ADDR1_REG: 0x%x\n",READ_PERI_REG(SENS_SAR_SLAVE_ADDR1_REG));

printf("Instruction: 0x%x\n",*(((uint32_t *)&program)+10));


And here is the output of the registers I am setting to get the I2C_RD to work. Instruction is the i2c_rd opcode from the rtc_slow_mem. Never returns from deep sleep :-(

Wakeup cause 0
Not ULP wakeup
RTC_TO_SAR_I2D_IO_REG: 0x10000000
RTC_IO_TOUCH_PAD1_REG: 0x4a080000
RTC_IO_TOUCH_PAD2_REG: 0x52080000
RTC_I2C_SCL_LOW_PERIOD_REG: 0x28
RTC_I2C_SCL_HIGH_PERIOD_REG: 0x28
RTC_I2C_SDA_DUTY_REG: 0x10
RTC_I2C_SCL_START_PERIOD_REG: 0x1e
RTC_I2C_SCL_STOP_PERIOD_REG: 0x2c
RTC_I2C_TIMEOUT_REG: 0xc8
RTC_I2C_CTRL_REG: 0x10
SENS_SAR_SLAVE_ADDR1_REG: 0xc000
Instruction: 0x3038000f
Exit init_ulp_program
Exit start_ulp_program
Entering deep sleep

Who is online

Users browsing this forum: No registered users and 58 guests