Datasheet
Expander_Init
354
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6
Prototype
void Expander_Init(char ModuleAddress);
Returns Nothing.
Description
Initializes Port Expander using SPI communication.
Port Expander module settings :
- hardware addressing enabled
- automatic address pointer incrementing disabled (byte mode)
- BANK_0 register adressing
- slew rate enabled
Parameters :
-
ModuleAddress: Port Expander hardware address, see schematic at
the bottom of this page
Requires
Global variables :
- SPExpanderCS: Chip Select line
-
SPExpanderRST: Reset line
- SPExpanderCS_Direction: Direction of the Chip Select pin
- SPExpanderRST_Direction: Direction of the Reset pin
must be defined before using this function.
SPI module needs to be initialized. See SPI_Init and SPI_Init_Advanced routines.
Example
// Port Expander module connections
sbit SPExpanderRST at PORTB.B0;
sbit SPExpanderCS at PORTB.B1;
sbit SPExpanderRST_Direction at DDRB.B0;
sbit SPExpanderCS_Direction at DDRB.B1;
// End Port Expander module connections
// Pointer to appropriate SPI Read function
char (*SPI_Rd_Ptr)(char);
...
// If Port Expander Library uses SPI1 module
SPI_Rd_Ptr = &SPI1_Read; // Pass pointer to SPI
Read function of used SPI module
SPI1_Init(); // Initialize SPI module
used with PortExpander
Expander_Init(0); // Initialize Port Expander