Software spi library, Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 266

Advertising
background image

mikroC provides library which implement software SPI. These routines are hard-
ware independent and can be used with any MCU. You can easily communicate
with other devices via SPI: A/D converters, D/A converters, MAX7219, LTC1290,
etc.

Note: These functions implement time-based activities, so interrupts need to be
disabled when using the library.

Soft_Spi_Config

Soft_Spi_Read

Soft_Spi_Write

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

258

MikroElektronika: Development tools - Books - Compilers

page

Software SPI Library

Library Routines

Prototype

void

Soft_Spi_Config(char *port, const char SDI, const char SD0,

const char

SCK);

Description

Configures and initializes software SPI. Parameter port specifies port of MCU on which
SDI, SDO, and SCK pins will be located. Parameters

SDI

,

SDO

, and

SCK

need to be in

range 0–7 and cannot point at the same pin.

Soft_Spi_Config

needs to be called before using other functions from Soft SPI

Library.

Example

This will set SPI to master mode, clock = 50kHz, data sampled at the middle of interval,
clock idle state low and data transmitted at low to high edge. SDI pin is RB1, SDO pin
is RB2 and SCK pin is RB3:

Soft_Spi_Config(PORTB, 1, 2, 3);

Soft_Spi_Config

Advertising
This manual is related to the following products: