| Electronics > Projects, Designs, and Technical Stuff |
| Longan Nano GDV32F103 RISC-V board with HTU21D temperature/humidity sensor |
| (1/1) |
| wnorcott:
Hello Friends, Here is a project I put together for the new Longan Nano GDV32VF103 development board a RISC-V 32 bit microprocessor, It is a nice really nice 108 MHz dev board that includes a 1" OLED display. You have to crawl before you can walk so here's my first project on RISC-V. Features beside the temperature and humidity reading of course; * Instruction profiling for performance measurement using RISC-V "instructions execute" and "instruction clock" registers: instret and cycle, counts # of instructions in main loop function * timer based interrupt and sleep on interrupt, spend about 98% of time sleeping in WFI instruction * button based interrupt, uses the BOOT button to switch from Fahrenheit to Celsius * prints the ratio of instruction clock cycles to instruction executed e.g. reflects how much time it is sleeping. In sleep mode the instruction clock is ticking but no instructions are executing. * somewhat random blinky of the 3 colored LEDs using the instret register as a sequencer The hardware is quite simple it's just a MEAS HTU21D temperature/humidity sensor I had lying around. More of the project is really my investigation of this chip. This is NOT an Arduino project. I am using the GDV32 firmware development library from GigaDevices the manufacturer of the chip. Code is written in C. This sensor has been used before in a few of my other projects MSP430, ESP32, etc. in the past but was using the Arduino IDE with those other boards. The development platform is Platformio running on Microsoft Visual Studio Code on Manjaro Linux. For debugging it I am using an RV-LINK which is just another Longan Nano board burned with debugging firmware. For programming and debugging the two boards connect to each other with an 8 pin JTAG cable. I started off by reading a blog post by 'Kevin' that explained the toolchain and by looking at examples from GD32VF103 Firmware Library written by GigaDevice. My project has a platformio.ini file and works fine: if you are not using a RV-LINK I suggest programming it with USB-C cable and choose 'dfu' as the upload protocol but for me being able to upload and debug with the JTAG interface is really great. I feel like learning a lot just stepping through code and looking at registers in the Platformio debugger using the RV-LINK. The project is simple but working example that demonstrate writing to the OLED display, communicating over I2C bus to get temperature- and humidity readings and checking their CRC bytes, also quite a few other interesting bits I figured out or cobbled together. Here is my Git repository with the code if you want to download it an run it i.e. do a 'git clone https://github.com/wnorcott/longan-nano-htu21d/' The actual code is here https://github.com/wnorcott/longan-nano-htu21d/tree/master/longan-nano-htu21d Here is the board it is just the Nano, the HTU21D and (2) external 4k7 pullup resistors on the SDA and SCL pins of I2C bus. The HTU21D board has its own internal pullup resistors that are disabled. Everything is 3.3V on this board and sensor. It is using IC20 but the code is written to allow either IC20 or IC21 to be used it's not hard coded to IC20 peripheral. The LCD library is the GDV32F103 SDK that comes with platformio. I spilled some coffee so the paper has stains on it in case you were wondering. Stripped some of the insulation on the SDA (yellow) and SCL (orange) wires so I could use a logic analyzer to play around with PulseView and how it interprets I2C procotol. The I2C communications protocol I got by reading the HTU21D datasheet. Also the temperature and humidity formulas to convert from raw numbers to useful values. Here's a closeup of display Temperature (C or F) and relative humidity RH a count of # of times BOOT was pressed and the banner FAHRENHEIT or CELSIUS number of machine instructions executed in this loop measured at start/end Overhead in machine instructions of measurement function itself: 6 instructions. It gets this by calling the instruction count twice in a row and substracting the two values: it is just 6 machine instructions. It consists of reading the 2, 32-bit registers and returning the result as a 64 bit number. High- and low 32-bits of "instructions retired count" instreth/instret this is a running count of machine instructions executed since the last hardware reset "cycl/ins" shows the value 'instruction clock ticks divided by instructions executed', i.e. a value around 65 which relfects it is spending most of the time in sleep mode t_count is the number of timer alarms one fires about every 3.1 seconds and it takes a reading displays and computes everything and goes back to sleep. Layout of the code gd32vf103_it.c interrupt handlers gd32vprofile.c instruction profiling methods I wrote main.c main program, setup of I2C and timers, getting measurements, display, blinky etc. systick.c a module written by/cribbed from GD that has delay_1_msec method that does a busy wait Next steps: play around with logging measurements to the attached micro SD card reader. Add a vibration switch to enable some other interrupt driven function when you shake the board. Add a realtime clock chip for data logging timestamp/temperature/humidity. Have fun with it. |
| kathy:
Look good, but why i can not see the 1" oled module on your pictures, there are a lcd screen on this system. |
| wnorcott:
You're right, I stand corrected. The display is a "0.96inch 160x80 IPS RGB LCD" thanks. |
| Navigation |
| Message Index |