ULP - 32 bits arithmetics
Posted: Thu Feb 20, 2020 3:01 pm
Hello guys,
I need to interface HX711 with ESP32 in deep sleep mode. That shouldn't be a problem because interfacing with HX711 is really simple, just putting some pins up, some pins down and read some pins and do some basic math.
The biggest challenge i'm facing right now is to work with 32 bits variable. At some point of the code i need to shift 1 bit left, and thats really hard to do because all 4 registers are 16 bits only. I'm having trouble right now at the line "jump b_lsb_1, 0x8000". Compiler gives me this error : "Jump adress is to far. Input text was eq.".
Code is below and i haven't finished yet, i'm trying to do part by part. If someone could please give me some advice of a easiest way to work with 32 bits variables on ULP or even a easiest way to interface HX711 with ULP ESP32, i would be very pleased.
PS: Sorry 4 PT-BR comments in the code , the parts that i have doubts are commented in english
Thank u very much,
Matheus
#include "soc/soc_ulp.h"
#include "soc/rtc_io_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc_cntl_reg.h"
.bss//Variaveis sao declaradas dentro da secao .bss
.global measurement_count
measurement_count: .long 0
.text//O codigo é feito dentro da secao .text
.global main
main://O codigo e iniciado aqui, equivale ao void setup()
jump loop
loop: //add0 = 9 adsk = 8
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S+9, 1, 1)//sobe add0
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S+8, 1, 1)//desce adsk
le_add0:
READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + 9, 1) // le gpio_num_15 = rtc gpio 13
and r0, r0, 1 // faz uma and do valor lido com 0x01
jumpr le_add0, 0, eq // se o valor de r0 for igual zero, volta para ler dnv r0
stage_rst
loop_count:
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TC_S+8, 1, 1)//desce adsk
and r0, r1, 0x8000 // R0 = R1 & 0X8000
jumpr b_lsb_1, 0x8000, // if R1 (LSB BYte) MSB BIT is 1, R0 will be equal to 0x8000 then jump to b_lsb_1
jump b_lsb_0 // if R1(LSB Byte) MSB bit is 0, R0 will be 0x0000
b_lsb_0: // R1 MSB Bit equal 0
lsh r0, r1, 1 // shift 1 bit left from LSB Byte
mov r1, r0
lsh r0, r2, 1 // shift 1 bit left from R2( MSB Byte)
mov r2, r0
jump loop_count
b_lsb_1: // R1 MSB Bit equal 0
lsh r0, r1, 0x01 // shift 1 bit left from lsb byte
mov r1, r0
lsh r0, r2, 0x01 // shift 1 bit left from msb byte
add r2, r0, 1 // add 1 to the value that correspondsto MSB bit from LSB byte that now is LSB bit of MSB Byte.
jump loop_count
I need to interface HX711 with ESP32 in deep sleep mode. That shouldn't be a problem because interfacing with HX711 is really simple, just putting some pins up, some pins down and read some pins and do some basic math.
The biggest challenge i'm facing right now is to work with 32 bits variable. At some point of the code i need to shift 1 bit left, and thats really hard to do because all 4 registers are 16 bits only. I'm having trouble right now at the line "jump b_lsb_1, 0x8000". Compiler gives me this error : "Jump adress is to far. Input text was eq.".
Code is below and i haven't finished yet, i'm trying to do part by part. If someone could please give me some advice of a easiest way to work with 32 bits variables on ULP or even a easiest way to interface HX711 with ULP ESP32, i would be very pleased.
PS: Sorry 4 PT-BR comments in the code , the parts that i have doubts are commented in english
Thank u very much,
Matheus
#include "soc/soc_ulp.h"
#include "soc/rtc_io_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc_cntl_reg.h"
.bss//Variaveis sao declaradas dentro da secao .bss
.global measurement_count
measurement_count: .long 0
.text//O codigo é feito dentro da secao .text
.global main
main://O codigo e iniciado aqui, equivale ao void setup()
jump loop
loop: //add0 = 9 adsk = 8
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S+9, 1, 1)//sobe add0
WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S+8, 1, 1)//desce adsk
le_add0:
READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + 9, 1) // le gpio_num_15 = rtc gpio 13
and r0, r0, 1 // faz uma and do valor lido com 0x01
jumpr le_add0, 0, eq // se o valor de r0 for igual zero, volta para ler dnv r0
stage_rst
loop_count:
WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TC_S+8, 1, 1)//desce adsk
and r0, r1, 0x8000 // R0 = R1 & 0X8000
jumpr b_lsb_1, 0x8000, // if R1 (LSB BYte) MSB BIT is 1, R0 will be equal to 0x8000 then jump to b_lsb_1
jump b_lsb_0 // if R1(LSB Byte) MSB bit is 0, R0 will be 0x0000
b_lsb_0: // R1 MSB Bit equal 0
lsh r0, r1, 1 // shift 1 bit left from LSB Byte
mov r1, r0
lsh r0, r2, 1 // shift 1 bit left from R2( MSB Byte)
mov r2, r0
jump loop_count
b_lsb_1: // R1 MSB Bit equal 0
lsh r0, r1, 0x01 // shift 1 bit left from lsb byte
mov r1, r0
lsh r0, r2, 0x01 // shift 1 bit left from msb byte
add r2, r0, 1 // add 1 to the value that correspondsto MSB bit from LSB byte that now is LSB bit of MSB Byte.
jump loop_count