Skip to main content

Posts

Showing posts from March, 2019

STM32 TIPS: Unique Device ID & Flash Size

Here is a random little post for you guys. Down at the bottom of your reference manual just before the ending sections usually reserved for debug support and revision history there is the "Device Electronic Signature" section. Its provides you with some device specific addresses where you will find a 96-bit unique device ID as well as the flash memory size for your device. Check out the code below to get an idea of how to read these values.



Memory Size Register The first thing we do is head over to the Reference manual page 825 for STM32L0 and page 1072 for STM32F1. This is where the Device ID and Flash Memory Size resister addresses are given. Observe below I have highlighted the physical address of this read-only register which yields the flash size of the device. The next step is to make an pointer directly to this address, it must be at-least a 16 bit integer given the size of the register. We can use the  stdint.h  library to make an integer exactly that wide, or just …

STM32L0/F0/F3 I2C : Part 2 Basic RX TX

Ok now for the fun part, CODING!! Below you can see every line of code for my main.c file. If you are using an STM32L0 and Keil without HAL or SPL this should compile just fine, otherwise sue me.



lines 1-3 are self explanatory. #include "Stm32l0xx.h"#include "stdint.h"#include "string.h"


6-9 are function prototypes for some functions I used, I would include them just for now because I did the timing calculation based on 32MHz and I also threw in  a delay in between read and write operations because the EEPROM needs some time to do that actual writing.
voidsetClockTo32Mhz(void); uint32_t msTICKS; voiddelayMs(uint32_t ms); voidSysTick_Handler(void);

22-25 I make some variables to store data, and the data which i will be transmitting as well as a counter variable to keep track of bytes sent. Note that on line 23 I add 1 to the length of string and hence the num_bytes, this is because on top of sending this string over I also have to send one byte consisting …

STM32L0/F0/F3 I2C : Part 1 Register Overview

Inter-Integrated Circuit is a common communications method  used for intra-board communications among ICs supporting the protocol. The maximum distance you can connect two devices when "on-board" is not an option depends on materials being used. Wire capacitance, resistor values, and frequency all come into play and will ultimately determine the maximum communicable distance. But that is not the subject of this post. We are here to learn about how to implement the I2C peripheral in the STM32LO/F0/F3 devices (they are all identical except for 1 bit described later). For more I2C specific knowledge check this site out: https://www.i2c-bus.org/ So lets take a crack at it. In this tutorial I will cover how to set up the microcontroller in master mode to be a receiver and transmitter. The microcontroller also supports being a slave, I may cover that in a later psot if anyone requests it. As the tutorial progresses I will introduce the AT24C02 EEPROM device which I will be using …

G0 Beyond the STM32F1

There is more to ST Microelectronics than the STM32F103C8 Microcontroller. They make a variety of sensors, mosfets, gate drivers, diodes,  and just about anything you can think of. However, within their microcontroller line there are an array of options. Typically divided into their respective target market. The famous STM32F1 started being produced in 2007, in technology years..its a dinosaur.  Nowadays STM offers  better designs that are not only more power efficient but easier to design for. Since 2007 a lot has chanced and STM is producing chips using a more advanced and smaller 90nm process versus the 130nm process in the F1. What that means is that STM is squeezing more transistors into their chips, thus packing more features into them and making them more power efficient. I own an STM32L0 board that I purchased to test some code I was working on for a freelance gig. The freelance work required that I used CubeMx HAL so I did not get a chance to look into the registers. However,…