SPI Modes

SPI knows 4 "standard" modes, reflecting the SCK's polarity (CPOL) and the SCK's phase (CPHA).

0 (or 0,0) 0 0
1 (or 0,1) 0 1
2 (or 1,0) 1 0
3 (or 1,1) 1 1

The meaning is:

  • 0 = Clock Idle low level
  • 1 = Clock Idle high level
  • 0 = SDO transmit edge (*) active to idle
  • 1 = SDO transmit edge idle to active
(*): the transmit edge is the clock edge at which the SDO level changes.

In a timing diagram this looks like(only one clock pulse shown here):

The Transmit edge is the clock edge at which the SPI output data changes,
The Sampling edge is the clock edge at which the sampling of the SPI input data takes place.
The sampling edge is normally the opposite one of the transmit edge.

References: www.rosseeld.be, dlnware.com

Suppress any warning in mbed Compiler

The mbed Compiler is a very usefull development platform for microcontrollers, but sometimes you will get warning messages, some of which you know about and want to be ignored. They appear on the first lines of "Compiler output" and you need to scroll down to reach the "real" compiler errors.

You can suppress specific compiler errors and warnings by using #pragma diag_suppress in the header of your project before any include happens.

#pragma diag_suppress sets a specific warning code or multiple warning codes and the compiler will ignore those warnings.

All the error and warning codes can be found on http://infocenter.arm.com website.


alternative link

References: developer.mbed.org/forum/, about diag_suppress tag, ARM compiler warning and error codes,

16 bit color generator (RGB565 color picker)

One of the previous notes was about 16 bits RGB color representationRGB565 format. This note will be based on that note and you will be able to generate any color, within 16 bit color depth, by using the color picker below.

Hexadecimal 24 bit color depth value:

Hexadecimal 16 bit color depth value:

Color picker with preview:

C++ array of pointers to objects

I was driving multiple TFT LCDs on the same microcontroller. Each LCD had its own instance and I needed an easy method of iterate through all of them.

The platform I used is a ST Nucleo F411RE board, the programming enviroment is mbed and the TFT LCDs are 2.2 inch ILI9341 display.

By using a single screen, the code could look like this:

On the other hand, by using multiple screens, the code could look like this:

The code is not elegant, but it gets the job done.
Note that the LCDs RST and CS pins need to be individually connected to the microcontroller.

Reference: www.java2s.com