Sunday, October 18, 2015

Adding BLE to your projects with HM-10 (CC2541)

Bluetooth Low Energy (BLE) or Bluetooth 4.0 is one of the latest bluetooth standard which is extremely popular since it enables designers to create systems that consume less energy unlike classic bluetooth. Proper adoption of BLE enables systems to run on power sources like coin cells and AAA batteries for years. BLE supports numerous profiles. If you're a beginner and looking to get started with BLE development, I would
recommend HM-10 BLE module which comes for around $3 on eBay, that pretty cheap for what it can do.

HM-10 on a breakout board

 HM-10 is based on Texas Instrument's RF chip CC2540 or CC2541. Usually if you buy the chip, you need to add a few passive components and an antenna to get things to work. But with HM-10 you do not need to worry. The module has all the components ready to work right out of the box. The module is manufactured by Huamao Technology Co. Ltd.

By default Huamao ships HM-10 with their special firmware that allows the user to control the module over UART using AT commands. A wide range of functionalities can be implemented using the AT commands so in most cases, you can simply achieve what you want using the AT commands without having to write your own firmware.

If you're planning to go beyond the default firmware and write your own, you're going to need a few tools:

1. TI 's CC Debugger for downloading your firmware to the module and also for debugging.
2. IAR Embedded Workbech for 8051 for writing your code and building your firmware
3. TI' s BLE stack

The sad part is that IAR Embedded Workbench is the only option to work with CC2540 and CC2541 chips and they offer only a 30 Day evaluation version which is simply not enough. The best way to tackle this is to use Virtual box.

TI's BLE Wiki is a useful resource when getting started with BLE development on TI chips.

Useful Documents:
1. CC Debugger User Guide
2. BLE Software Development guide
3. CC2541 Hardware Guide

This post has just covered the basic that you need to setup to get started. Stay tuned to more posts on hands-on with HM-10 module.

Sunday, April 19, 2015

Get started with ARM development on STM32F411RET6

For a pretty long time I have been wanting to lay my hands on some sort of ARM based microcontrollers. There were too many options out there and never knew how to get started with it. Recently I came across ST Microelectronics. They have an awesome collection of low cost ARM based evaluation boards. Then I came across their Nucleo series and I decided to get one at the top of the series, the NUCLEO F411RE. What excited me is that it is cheaper than an Arduino Uno. ST has a number of low cost ARM evaluation boards.

Now coming to the point, the NUCLEO F411RE is based on the STM32F411RET6 32 bit microcontroller which has an ARM Cortex M4 architecture at its heart with a maximum clock speed of 100 MHz. That is roughly 6.25X the speed of your Arduino Uno. The best part is that the evaluation board is supported by mbed.

Mbed is an venture from ARM holdings and its numerous technology partners including Atmel, FreeScale, IBM. It is basically a free online compiler platform for ARM-M series microcontrollers where you can type in your code, compile and download the bin file for flashing onto your device. I would call mbed as an Arduino equivalent when it comes to the compiler part. There are numerous libraries available to take care of your digital I/Os, timers, PWM etc. So this is a good starting point even if you haven’t gone beyond the 8bit devices. Importing of libraries is pretty easy and there is an awesome forum to resolve all your issues. It also relieves you of finding a good compiler and IDE for ARM development. It also offers good code portability since the library functions are the same for different microcontrollers. But making use of the pre-built libraries robs you of the knowledge of what’s really happening inside and often keeps you away from exploring the full potential of your device. So this post is going to be about register level programming of NUCLEOF411RE.

First logon to Instructions to get everything up and running is provided there. Now for the hardware part, you can follow this link to configure any NUCLEO board:
Once you have setup your Nucleo board and mbed account, it’s time to get some code running on that 32 bit device.

I won’t be walking you through the code. But I’ll be telling you the basics needed to get an led to blink. I chose to connect my led to the first bit(LSB) of GPIOA of STM32F411RET6.

At the start of the code you’ll have to include mbed.h. This will take care of a few memory related setup you’ll have to do otherwise.

First of all you need to turn on the clock supply to whatever peripheral you are planning to use. In this case it is GPIOA. If you refer the datasheet, the  clock supply to GPIOA can be turned on by setting the LSB of RCC_AHB1ENR.

Next register is the GPIOx_MODER. This is the register where you decide whether a GPIO pin is going to be an input or an output. X is the GPIO port eg. A,B,H etc.
The next one is GPIOx_OTYPER. The microcontroller offers different types of output configuration. You can chose either push-pull, open drain configuration using this register. GPIOx_ODR is the register whose contents will be reflected at the GPIO pin i.e a set bit will set the corresponding pin to a logic high and a reset bit will set it to logic low(0 V, almost).

For the time being you’ll need to use only the above mentioned registers. But there are four other registers worth mentioning. GPIOX_BSRR which can be used to set or reset individual bits. GPIOx_LCKR which can be used to lock other registers associated with GPIO to ensure that they are not modified accidentally. GPIO_AFRH and GPIO_AFRL are used to configure the IOs having dual functionalities.

The code for blinking an LED on PA_0 has been uploaded on GitHub.

All the best with your foray into the ARM world.

Sunday, November 9, 2014

Detect the port to which Arduino is connected

 When interfacing an embedded system with a computer, it often becomes necessary to find the COM port to which the device is connected. This will enable the application running on the computer to home in on the target device.

The methodology is to let the target system to continuously send messages over the COM port to the computer system. The application on the computer, checks each COM port for the particular message and flags when the message is received from a COM port. The application can send back a keyword to the embedded system to stop transmitting the message since it is no longer needed.

I wrote a c++ application just out of curiosity to identify the port to which my Arduino was connected. In the setup I used, the Arduino continuously transmitted  the word "hello". The app checked for this message and identifies the port from which the message was received. I thought it might might be useful to put up the code so that someone else might find it useful. A screenshot of the application is shown below:

 I am adding the source code and the library files required. The Serial library files needed for the purpose was found on the Arduino website. With fair amount of tinkering, I was able to get things running. The app was coded using Visual Studio 2013 Ultimate Edition.

The project can be downloaded from GitHub

Sunday, August 24, 2014

Exciting world of FPGA

I have been in the embedded domain for a while and has a fair share of experience with those tiny 8-bit devices. FPGA (Field Programmable Gate Array) caught my attention recently and is one of the hottest things in the electronics industry at the moment. FPGA is probably the closest you can get near to achieving real time processing.
So what all the hype around FPGA? Anyone who has fiddled with embedded systems will know that processors are never real time. They execute lines of codes one after another. They appear to work in real-time for a wide variety of applications because they execute the code pretty fast. To put things into simple words, suppose that you put up a simple microcontroller circuit to turn an LED ON when a switch is pressed and turn it OFF when the switch has been released. Just a few lines of code will achieve this and the microcontroller will execute the code over and over again so many times in a single second. Think that you are a super fast human being capable of clicking the switch on and off REALLY fast such that you can push the switch ON and turn it OFF before the microcontroller executes the line of code which check if the switch has been pressed or not, you’ll never see the LED turn ON just because you microcontroller never detected the press of the switch. This makes the software or code based embedded systems non-real time.
When it comes to FPGAs things are totally different, there is no line by line execution of code. If you do the same LED operation as mentioned above, what happens is that a direct connection is established between the switch and LED, just like you would do on a breadboard. So you are going to see the LED light up every time you turn the switch ON.
What’s more exciting is that you can implement a number of such units on the same chip and all of those units will run in parallel i.e. you can have a single FPGA to so some serious image processing, blink some LEDs, drive motors all at the same time. Really cool!!!!


Altera and Xilinx are the forerunners in FPGA manufacturing. To implement a logic on FPGA, the configuration files are creates in a suitable Hardware Description Language (HDL) like Verilog or VHDL and are downloaded to the FPGA. FPGAs are wiped clean i.e. goes blank when they are powered off. So you always need an external memory to hold the configuration files from which the device can be reconfigured every time it boots up. Most FPGA development boards come with an on-board storage facility to store the config files. The data is not stored exactly as a file. It will be a stream of bits stored in a PROM chip.

Monday, January 20, 2014

A deep introduction to MOSFETs and its working

I have recently fallen for MOSFETs. These incredible power semi-conductor devices simply amazes me. MOSFET is the acronym of Metal Oxide Semi-Conductor Field Effect Transistor.

It is basically a 3-terminal device(even though you might find a 4th one in a few)-the drain, source and gate. It is often an important element in power control applications They are used in numerous devices-inverters, motor drives, SMPS to name a few.

It is basically a switching device in which the conduction between the drain and source can be controlled using the voltage between the source and gate terminals. You have to apply a voltage above the threshold voltage of the FET to turn it on. This value can be found in the datasheet.. At first the conduction increases( drain current) linearly and then it attains saturation values( maximum value).

The name Metal Oxide Semiconductor comes from the fact that the gate is made up of three layers-metal, an oxide layer and a semi conductor. A channel exists between the drain and source terminal whose character differs depending on the type of MOSFET. The channel lies below the insulator at the gate. The conduction between gate and source happens when the channel is filled with sufficient number of free charges.

There are two different types of MOSFETs: enhancement type and depletion type. Enhancement type requires you to enhance its conductivity by applying suitable gate to source voltage or the transistor is OFF by default (application of voltage creates free charges in the channel). On the other hand, depletion ones needs suitable gate to source voltage to stop its conduction or they are ON by default( consists of free charges without the application of voltage). In addition to this a further sub division NMOS and PMOS exists. The former one conducts using free negative charge and the latter one using free positive charge or holes. Enhancement type NMOSFET is the most widely used one due to a number of factors.

If you look at the figure, the topmost layer of the gate terminal is the metal, the white one is the insulating oxide layer usually made of Silicon dioxide. Below that is the semiconductor. When a voltage is applied between gate and source, the insulator does not allow the voltage to go directly to the semiconductor. Instead, a capacitive effect occurs where the plates of the capacitor are the metal and the semiconductor layers and the oxide layer serves the purpose of the dielectric medium. The B terminal is the body terminal and serves to control the threshold voltage. This is not often provided.

Take the case of enhancement type NMOSFET, a positive gate to source voltage induces positive charges on the metal and an equal and opposite charges develop in the semiconductor layer which is actually the channel. Now a path which consists of sufficient number of free charges exist and conduction can happen between drain and source. But for the conduction to occur, the gate voltage has to be above the threshold levels. Removal of the voltage diminishes the conducting channel and the conductivity comes to a halt. 

A typical MOSFET offers an OFF resistance in the order of Mega ohms whereas the ON resistance is within a few ohms. 

This figure shows how the channel is formed and the drain current increases and saturates with increase in gate voltage.  

The various symbols of MOSFET are:

The schematic shows the use of a MOSFET for driving a load, here it is an LED:

Here the transistor is acting as a acting as a a low side driver i.e the MOSFET connects and disconnects the lower voltage, in this case ground, from the load. The resistance between gate and source is to prevent any false triggering and also for discharging the stored charges in the gate during turn off.

A lot of things have to be considered when using MOSFETs and other power control devices. I'll be posting more about MOSFETs. The upcoming posts will be on low side, high side driving and gate driver ICs like IR2111. I simply love them, they amaze me.