Showing posts with label Microcontroller SiLabs. Show all posts
Showing posts with label Microcontroller SiLabs. Show all posts

Friday, March 15, 2024

Delay functions for Silicon Labs microcontrollers

Sometimes you need to delay the program execution, for example when waiting for another device to startup or respond and the software cannot continue. An interrupt driven delay is better in most cases but not in all cases. For this purpose I made two functions one for milliseconds and one for microseconds, that uses NOPs to delay the program execution for a certain amount of time. The milliseconds delay is quite accurate, the microseconds one, not so much.

For this to work, the SYSCLK must be defined first. It is recommended to be defined in the project settings. You can find a short tutorial here on how to add a global define in Simplicity Studio: https://www.programming-electronics-diy.xyz/2024/03/defining-sysclk-or-fcpu-in-simplicity.html

Tested on:

- C8051F330

For other microcontrollers the following SFR declarations include file should be replaced accordingly:

#include <SI_C8051F330_Register_Enums.h>


Library usage

 

Milliseconds delay

 
_delay_ms(uint32_t ms)
 

Microseconds delay

 
_delay_us(uint32_t us)

I couldn't figure a way to make millis delay more accurate since the code used to create the delay, adds delay and cannot be easily subtracted because it depends of the delay time. I think it should be implemented using assembly but i don't know the language. If you need just a certain delay time, you could tweak the function for that particular delay, using a logic analyzer.

Download

delay
v1.0 delay Contains delay.h and delay.c

UART library for Silicon Labs microcontrollers using interrupts

This UART library is made for Silicon Labs microcontrollers that can be used for serial communications.

UART is a type of serial interface, as opposed to a parallel interface. A parallel interface can work at higher speeds but the disadvantage is that it needs multiple input/output lines. Other examples of serial interfaces are SPI and I2C. 

UART library for Silicon Labs microcontrollers using interrupts

Supported Devices

At the moment only following devices are supported. I might add more in the feature. It might work for other similar devices not listed below.

  • C8051F330

Defining SYSCLK or F_CPU in Simplicity Studio

The macro SYSCLK or F_CPU specifies the CPU frequency and is used by libraries such as <delay.h> to calculate the delay based on the frequency of the processor or by UART libraries to calculate baud rate.

Up until now I used to define F_CPU like this:

#define F_CPU    24500000UL

Defining this way will work but it could lead to issues and confusion when you have multiple files that define this macro. The ideal way is to define it in a single place. This could be a Makefile if you are using custom Makefiles or in the IDE project configuration.

Defining SYSCLK / F_CPU in Simplicity Studio

Open the project properties window in Project -> Properties (Alt+Enter) then in the left panel select the C/C++ Build -> Settings menu. Then in Tool Settings - > Keil 8051 Compiler -> Symbols use the green + button to define a new symbol SYSCLK=2450000UL. Of course the SYSCLK value depends on your CPU frequency that in this example is 24500000 Hertz or 24.5MHz. The UL at the end stands for unsigned integer.

Defining SYSCLK symbol in Simplicity Studio 01

Defining SYSCLK symbol in Simplicity Studio 02

That's it. Now all included files in your project will use a single SYSCLK value without giving errors such as "SYSCLK is not defined", "SYSCLK redefined", etc.

Since this method of defining is not as obvious as the first one, it is easy to forged to do it when starting a new project but there is a simple solution for that - using preprocessor conditionals.

#ifndef SYSCLK
	#warning	"SYSCLK not defined. Define it in project properties."
#elif SYSCLK != 24500000
	#warning	"Wrong SYSCLK frequency!"
#endif

This macro can be placed at the beginning of the main.c file before any type of code. If the SYSCLK is not defined it will output a warning. If SYSCLK is defined but is not the value specified in the macro, it will also output a warning. This is also helpful to see what the CPU frequency is and to ensure that the defined value in project properties is correct.

Tuesday, March 5, 2024

Open source software for programming Silicon Labs microcontrollers using C2 interface

The C2 Programmer is designed for programming Silicon Labs microcontrollers over the C2 interface by the use of an AVR microcontroller with the necessary firmware and an USB to serial adapter. The software is written in JavaScript and is based on ScriptCommunicator by Stefan Zieker.


Custom open source C2 programmer


What does it do

  • Save flash memory to .bin (binary), .txt (hex format) or .hex (Intel hex) file.
  • Write an Intel hex file to flash memory.
  • Erase device option.
 

Contents


Motivation

Why use a custom programmer when you can buy one? The reason I have started developing this software is not necessarily cost related. I could have just bought a programmer and be done with it instead of coding hours and hours, but I thought it will be a good addition for the community since being custom made it can be... customized. There are other reasons such as, maybe the commercial one is not available in your area or not in stock, or you might want to program only one or two microcontrollers and consider is not worth investing in a programmer.

Actually this is how the project started. I have an RDM-6300 RFID card reader that I thought is a writer too. Then I saw it's using the C8051F330 microcontroller from Silabs and decided to give it a try and make it also write RFID cards or at least add support for other chips. By not buying a programmer I made one that I could use in my project and also make it available for others.

Note that debugging is not supported so if you need this feature, consider buying a commercial programmer.

Theory of operation

Application on the computer instructs the firmware on an AVR microcontroller on what commands to send to the C2 interface of the programmed device. The communication between computer and programming device (the AVR) is done using an USB to serial converter. 

C2 programmer diagram

The application is build on top of ScriptCommunicator which is a scriptable cross-platform data terminal that supports serial port (RS232, USB to serial), UDP, TCP client/server, SPI, I2C, and CAN. Script Communicator it's an awesome application that unfortunately is not that well known. The best part is that the interface can be made to look how you want by using the Qt Designer included with the app.

Thursday, June 25, 2020

How a POV propeller display works

In part 1 on How to make a POV display we talked about the hardware and schematic. In this part 2 we will dive in how the code works and why the POV (Persistence Of Vision) display is so cool and fun to play with.

How a POV display works

Monday, December 31, 2018

ESP8266 library for EFM8 microcontrollers - Server mode

In previous article ESP8266 library for EFM8 microcontrollers was presented the ESP8266 module and how can be interfaced with a microcontroller in client mode. This article covers ESP8266 in server mode and how to send commands to ESP8266 over the internet.

Of course this is not a real web server although with an SD card whole HTML pages could be served. The purpose of this library is to extract queries from a URL requested by a client. This way for example you could change color and brightness of an RGB led using a color wheel in a phone app or control home appliances from anywhere in the world.



Saturday, December 8, 2018

ESP8266 library for EFM8 microcontrollers

ESP8266 is a low-cost serial to Wi-Fi module that is very popular among electronics hobbyists. It can be used to connect a microcontroller to internet over Wi-Fi. The things you can do with it are numerous. You could monitor and log various sensor data like atmospheric pressure, temperature and humidity together with geo locations on websites like thingspeak.com. Or you could retrieve information from internet such as weather, number of subscribers on YouTube, send tweets with your microcontroller, send email notification if your plants get dry, etc.


Tuesday, March 27, 2018

LC75824 LCD driver chip library for EFM8 microcontrollers

LC75824 is an LCD driver chip. It has 4 commons so it has 1/4 duty and supports 1/2 and 1/3 bias voltages. In addition to being able to directly drive up to 204 LCD segments, the LC75824E and LC75824W can also control up to 12 general-purpose output ports. Serial data input supports CCB format communication with the system controller.
The interface between the LCD driver and the microcontroller is done by using only 3 pins (CLK, CE and DATA).
I know this is an old and rare LCD driver but the library code can be used to adapt other LCD drivers. I use this because I have a broken Samsung MM-N7 audio system with a good display using this IC.

LC75824 pinout
LC75824 pinout

Sunday, March 4, 2018

UART library for EFM8BB1 Busy Bee microcontrollers


This UART library is made for EFM8 microcontrollers. It uses circular buffers for transmission and reception of data. This way large amounts of data can be sent or received with only 5 or 10 bytes per buffer, thus saving memory.
Uses 8 data bits, 1 stop bit, no parity. Supported baud rates: 9600, 14400, 19200, 38400, 57600, 115200, 128000, 256000.



On EFM8BB10F8G-A device, the UART pins are on port 0 and pin 4 is TX and pin 5 is used for RX.

EFM8BB1 SOIC16 pinout

Friday, March 2, 2018

Cheap and powerful 50 cents microcontroller | EFM8 Family

This is a step-by-step tutorial on how to setup and program an EFM8BB10F8G-A microcontroller or any other EFM8 Busy Bee microcontroller family from Silicon Labs. It is assumed that the reader knows the C programming language and basics about microcontrollers.
EFM8 Busy Bee microcontroller family from Silicon Labs
Why would you want to learn to use another microcontroller when there are many tutorials and libraries on popular MCU's such as AVR and PIC? Well, because they are much more cheaper but performant nonetheless - on Farnell you can buy them for less than 50 cents - and also are pre-programed with a bootloader making easy to program them using any USB to serial converter.  Compare that to Attiny13A which is around the same price but with half the pin count, less speed and peripherals. Just see the features bellow.