UsingSwordfishWithMikroBUSClickAdapterBoards

The MikroE family of Click boards is an ever expanding collection of boards that provides easy interfacing of a variety of sensors, communications, and displays using the mikroBUS standard.

The mikroBUS consists of three groups of communications pins (SPI, UART and I2C), six additional pins (PWM, Interrupt, Analog input, Reset and Chip select), and two power groups (+3.3V and 5V).

The full specification is available here

There are a number of development platforms available that support the PIC18, including:

  • Microchip Explorer 8 (DM160228) and Curiosity High Pin Count (HPC) Development Board (DM164136)
  • MikroE Clicker2 for 18FK 67K40 (MIKROE-2584), and Pic Clicker 47J53 (MIKROE-1487)
  • MikroE UNO Click shield (MIKROE-1581) with Firewing08 PIC18 board

Each one has advantages and disadvantages, such as shared periperals, limited device selection, etc. Some only support a single device or mikroBUS socket. I'd suggest looking over the schematics closely before buying one.

For most of the example code I used the MikroE UNO Click shield and the Firewing PIC18 board (aka "FW18")

This combination allows for 2 mikroBUS sockets and works reasonably well with 28-pin devices such as the 18F26K22 and 18F2xK40 or Q10. There are some restrictions, however that should be addressed.

  1. mikroBUS uart is connected to UART1, which is normally used by the FW18 USB-UART main board.
  2. mikroBUS INT_D2 and INT_D3 signals connect to the FW18 board ICSP RB7 and RB6 pins, so using the ICD is problematic.

mikroBUS UNO shield

Fortunately, there are a number of unused pins on the UNO Click shield so a few simple cuts and jumpers to the UNO shield fix both of these issues. The modifications are discussed in the file mikrobus_shield.txt, but I'll outline them here:

UNO click shield modification summary

	- cut track @ HD3-5 (PD3/INT1)
		this isolates FW18 RB6_PGC_D3 for icsp use (J8-4)
	- cut track @ HD3-6 (PD2/INT0)
		this isolates FW18 RB7_PGD_D2 for icsp use (J8-3)
	- jumper mikrobus1 INT_D2 to HD2-1 (NC)
		this connects mikrobus1 INT_D2 (PD2_INT0) to FW J5-1 NC_D14_RA4
	- jumper mikrobus2 INT_D3 to HD3-4 (D4)
		this connects mikrobus2 INT_D3 (PD3_INT1) to FW J8-5 D4_RC0
	- jumper HD3-1 (D7) to mikrobus RX_D0
		map FW18 D7_RB5 to uart2 RX via PPS
	- jumper HD4-10 (D8) to mikrobus TX_D1
		map FW18 D8_RB4 to uart2 TX via PPS
	- place SW1 in the PROG position
		this isolates RX and TX from HD3 disconnecting them from FW usb-uart 
		(FW18 J8-1 RX_RC7, J8-2 TX_RC6)

new signal mapping:

	D3_INT -> D4_INT  (RC0)
	D2_INT -> D14_INT (RA4)
	D1_TX  -> D8_TX   (RB4) UART2
	D0_RX  -> D7_RX   (RB5) UART2
	D3  unused, reserved for FW ICSP (RB6)
	D2  unused, reserved for FW ICSP (RB7)
	D1  unused, reserved for FW USB-UART1 (RC6)
	D0  unused, reserved for FW USB-UART1 (RC7)

Device Selection

The standard 18F2xK22 works with one limitation- UART2 is shared with the ICSP pins on RB6/RB7, so if you want to use ICD for hardware debugging the mikrobus uart must be done using software. The module hwsuart_FD.bas contains a hardware-assisted full-duplex uart to support this.

A better choice of devices is the 18F27K40 (or 18F27Q10) as these contain two EUSARTS mappable via PPS. This is the most flexible, and the only down-side is that you must use MPLABX for debugging.

Click board Power

Most of the Click boards are jumper-selectable to use either 3V3 or 5V, and typically come set for 3V3. Be sure to set the FW18 main board Vsupp power select jumper to match. Do not mix 3V and 5V boards.

Demo Code

main_fwuart.bas
this is a simple example of using the main board USB-UART (just to check out basic operation)

eeprom_click.bas
I2C example using mikroe EEPROM click (MIKROE-1200) with a 24C08WP

expand_click.bas
SPI example using mikroe EXPAND click (MIKROE-951) and the MCP23S17 SPI 16-bit IO expander

main_fw18_mbus_uart.bas
UART example using mikroe RS232 click (MIKROE-1582) using both the mikroBUS uart and the FW18 USB-UART

These are all a "work in progress", so they likely require a little tweaking to match your setup.

fw18_mikrobus_v1.zip