Posts

Stm32F103C8T6 bluepill controls RGB LED WS2811 IC non-DMA method

Image
STM32F103C8T6 bluepill controls RGB LED WS2811 IC using non-DMA method   IDE: STM32CubeIDE MCU: stm32F103C8T6 bluepill or black pill (STM32F401CCU6)  Category: RGB LED IC: WS2811 ( Using a RGB LCD Screen, it has 3 RGB Leds, 3 WS2811 ICs) Oscolliscope: useful and helpful Intro   There are quite some tutorials in Internet about the topic, however many of those are using DMA method. DMA is very useful in many use cases however not in mine, so I decided to investigate the non DMA method. I want to simply toggle GPIO to send the correct signal to the IC to make it work. WS2811 is a RGB IC, each IC controls one RGB LED (Neopixel ?), for example if we have 3 RGB LEDs, we need 3 WS2811.   Any WS2811 RGB product should work with this source code / method, I am using a RGB LCD screen, It's made by Makerbase and made for 3D printer / Marlin firmware to use, originally. Since I don't have any RGB LED strip, this RGB LED is a very good test candidate. In case you have the sa...

Using STM32 DMA to speed up hardware SPI and U8G2 - Attempt 2 - buffered DMA

Image
Using STM32 DMA to speed up hardware SPI and U8G2 - Attempt 2 - buffered DMA So we have tried the simple DMA method, simple DMA method which doesn't work, let's try another way. In this test, we will cache everything the u8g2 trys to send to the LCD screen over SPI, then we will find a good chance to send the whole huge buffer to LCD using SPI DMA. Step 1 store data to our buffer define a function to be put inside the SPI back function for message U8X8_MSG_BYTE_SEND. cache_spi_data_to_buffer_for_dma_u8g2_callback this function doesn't send anything at all, it only cache the data into our DMA buffer. Since STM32 bluepill has 20kb and blackpill has more, so it's easy for us to spare 2.65KB for u8g2 and LCD DMA buffer. According to my tests so far, every time we call u8g2 sendbuffer() function, all the accumulated data before the last EndTransfer call, the total transmitted size is 25XX, so 2.65KB should be enough for our buffer size. Step 1.1 In this store and cache f...

Using STM32 DMA to speed up hardware SPI and U8G2 - Attempt 1 - Simple DMA

Image
Using STM32 DMA to speed up hardware SPI and U8G2 - Attempt 1 - Simple DMA   So we have finished all the basic hardware connection, setup and using hardware SPI to let u8g2 to communicate to LCD12864. Please check this post for detail: STM32 and U8G2 to draw on LCD12864 Using hardware SPI It works well, however there is a tiny problem, it's too slow. The speed problem of SPI of LCD12864(ST7920) Every time we call u8g2.sendBuffer(), this operation takes 43milliseconds. How to measure sendbuffer() 's time usage in stm32cubeIDE:     uint32_t start_ts = HAL_GetTick();     u8g2.sendBuffer();     uint32_t end_ts = HAL_GetTick();     unsigned int delta_msec = end_ts - start_ts;     printf("sendbuffer used %u ms\r\n", delta_msec);   Using stm32F103C8T6 bluepill, system speed 72Mhz, spi speed 572kbit/s Without doing much (just write some text) in the main loop, the LCD screen just have a FPS about 16FPS ( with...

STM32 and U8G2 to draw on LCD12864 Using hardware SPI

Image
STM32 bluepill and U8G2 to draw on LCD12864 Using hardware SPI   Since there are not a lot of info about this on Internet, so I am making this guide. We can see some info/guide or example about using Arduino board, or Arduino IDE, or Software SPI to draw using U8g2. But in this guide, we will use hardware SPI, Stm32 chip, and use Stm32CubeIDE to draw. Keyword here: Bluepill, blackpill, u8g2, LCD12864(5V, works with 3.3V stm32 MCU), hardware SPI communication, Stm32CubeIDE.  Part List in the test: LCD12864 screen, Bluepill dev board(stm32F103C8T6) or Blackpill dev board( stm32F401CCU6), 5V power supply, stlinkV2 device to flash or debug.   Low cost LCD12864 (ST7920), it's large, and good resolution(128X64), cheap. It has a lot of pins for parallel connection, DB0 DB1 DB2...DB7, but who has so many pins to connect?? In fact, this LCD can support SPI connection, it only need 2pins to MCU: MOSI and SCK, CS and RESET is optional, no need to connect to MCU.   In SPI mode, ...

Temperature Sensor Thermocouple API for MCU like Arduino

Image
 Temperature Sensor Thermocouple API for MCU like Arduino This library added a few API for Arduino and similar MCU to easily work on a common temperature sensor - thermocouple. K type in this library but can be easily add support for other type like JType thermocouple. In this test, I use the KType thermocouple from a multimeter, which seems works well on a few different brands of multiple. Theory of operation Thermocouple produce a tiny voltage when it has temperature different than the environment or cold end, the tiny voltage can not be detected by arduino ADC directly, we must add a opAmp to amplify it a hundred times, so arduino ADC can correctly read it. Any opamp works, I am using MCP6002 here. (The popular and cheapest LM358 works too, however need to pay attention LM358 doesn't work well in 3.3V system. ) D3 is optional, to limit the input. Software and Algorithm: There are a few ways to work on the opAmp output voltage. The easiest but not accurate:  using voltage pe...

Super DIY 2020 Desktop CNC for milling PCB

Image
Super DIY 2020 Desktop CNC for milling PCB Project objective: Make a low cost desktop CNC to mill PCB, using standard aluminum 2020 extrusion as frame, and brushless motor as spindle. Since we need to mill PCB, some component's footprint is tiny, so the CNC has to be precise enough to mill trace and clearance of 0.2mm. The Finished Product: Back Ground: I always want to make a desktop CNC to mill custom PCB for rapid prototyping, this project was inspired by some other creative people's CNC designs, specially the ANT team ( https://www.youtube.com/c/TheAntPCBMaker ), however I do have a lot different opinions for some design choices. So after one year's work, I designed, rework, redesigned, reprint, rework again...for many times, finally this Super 2020 desktop CNC is sort of finished. Design consideration: It has to be small enough, as a desktop CNC, it's not for milling large piece of wood, it's made for PCB, the most common PCB size is 10cmX15cm, so the CNC is d...