User manual
mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
472
SPI_Set_Active
Prototype
procedure SPI_Set_Active(read_ptr : ^TSPI_Rd_Ptr; write_ptr : ^TSPI_Wr_
Ptr);
Description Sets the active SPI module which will be used by the SPIx_Read and SPIx_Write routines.
Parameters Parameters:
- read_ptr: SPI1_Read handler
- write_ptr: SPI1_Write handler
Returns Nothing.
Requires Routine is available only for MCUs with multiple SPI modules.
Used SPI module must be initialized before using this function. See the SPIx_Init and SPIx_Init_
Advanced routines.
Example
SPI_Set_Active(@SPI1_Read, @SPI1_Write); // Sets the SPI1 module active
Notes Number of SPI modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.
Library Example
The code demonstrates how to use SPI library functions for communication between SPI2 module of the MCU and
MCP4921 DAC chip.
Copy Code To Clipboard
program SPI;
// DAC module connections
var Chip_Select : sbit at LATF0_bit;
Chip_Select_Direction : sbit at TRISF0_bit;
// End DAC module connections
var value : word;
procedure InitMain();
begin
TRISB0_bit := 1; // Set RA0 pin as input
TRISB1_bit := 1; // Set RA1 pin as input
Chip_Select := 1; // Deselect DAC
Chip_Select_Direction := 0; // Set CS# pin as Output
SPI1_Init(); // Initialize SPI module
end;
// DAC increments (0..4095) --> output voltage (0..Vref)
procedure DAC_Output( valueDAC : word);
var temp : byte;
begin
Chip_Select := 0; // Select DAC chip
// Send High Byte