piconomix / px-fwlib

open source bare-metal C firmware and documentation for microcontrollers
Other
281 stars 27 forks source link
arduino-uno avr c microcontrollers stm32

MIT license

:warning: Project name change notice

Apologies for any inconvenience caused. The Git project name has been shortened from "piconomix-fwlib" to "px-fwlib". Here is the Git command to change your cloned repo's URL:

git remote set-url origin https://github.com/piconomix/px-fwlib.git

The online documentation URL has changed to:

https://piconomix.com/px-fwlib/index.html

PX-HER0 Board

STM32L072 PX-HER0 Board now in stock at Crowd Supply! Click HERE

Introduction

https://piconomix.com

px-fwlib is a collection of open source C firmware and documentation for microcontrollers to develop portable bare-metal code that is vendor and architecture neutral (or easier to reuse).

It is tough to find the best compromise between lean 8-bit targets, middle-of-the-road 16-bit targets, and resource rich 32-bit targets, but this cross-platform library aims to provide a good foundation before you are forced to add target specific code and getting locked in.

Click HERE to view the complete online documentation.

Click HERE to download releases of the open source library (source code and offline documentation).

Goals

My sincere hope is that seasoned veterans will pitch in and share their years of experience to mentor the future generation and raise the bar in terms of quality and quantity.

Example

Included with the library is a CLI (Command Line Interpreter) executing on an Arduino Uno R3 that creates an interactive shell environment so that you can experiment with GPIO, ADC, I2C and SPI using only an ANSI/VT100 terminal emulator (for example Tera Term).

Electrodragon BMP280 breakout board connected to I2C

Connect your board, fire up the CLI and verify that it works:

CLI Exlorer executing on an Arduino Uno R3

The BMP280 is found at 7-bit slave address 0x76. The chip identification register value for the BMP280 is 0x58. This confirms that you are able to write to and read from the I2C slave.

After verification, it is easy to accomplish the same in C using the library:

#include "px_i2c.h"
#include "px_board.h"

// Bosch BMP280 I2C Slave Address
#define I2C_SLA_ADR   0x76

// Create I2C Slave handle object
px_i2c_handle_t px_i2c_handle;

int main(void)
{
    uint8_t data[1];

    // Initialise board
    px_board_init();
    // Initialise I2C driver
    px_i2c_init();
    // Open handle to I2C slave device
    px_i2c_open(&px_i2c_handle, PX_I2C_NR_0, I2C_SLA_ADR);

    // START I2C write transaction and write register address
    data[0] = 0xd0;
    px_i2c_wr(&px_i2c_handle, data, 1, PX_I2C_FLAG_START_AND_END);
    // REPEATED START I2C read transaction and read register value
    px_i2c_rd(&px_i2c_handle, data, 1, PX_I2C_FLAG_REP_START_AND_STOP);

    // Close I2C Handle
    px_i2c_close(&px_i2c_handle);
}

License

MIT license

The MIT license has been selected to grant freedom for both open source and commercial (closed source) projects and to nurture future growth of the library. Please see the LICENSE.

Important Links

Questions or Feedback?

Questions or feedback (positive and negative) is great and will help to improve the library:

Feedback

Methods of communication:

Support

A significant amount of time has been invested to craft and refine this free open source library. If you saved development time, acquired a new skill, or advanced your career, you are welcome to support this project with a visit to the shop.

Shop Click HERE to visit the shop