AN1905 ST Microelectronics, Inc., AN1905 Datasheet - Page 47

no-image

AN1905

Manufacturer Part Number
AN1905
Description
St7mc Three-phase BLDC Motor Control Software Library
Manufacturer
ST Microelectronics, Inc.
Datasheet
ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY
4.3.4 ports.c
The purpose of the ports.c module is to centralize all information regarding the I/O ports (in-
cluding the alternate functions) within the same file.
It is intended to clarify the sharing of I/Os between the peripherals and the functions requiring
standard input/outputs, such as LEDs and push button reading.
I/Os are initialized at the beginning of the main program, using the ‘void PORTS_Init(void)’
function. Two functions are handled by this module, needed when running the software library
with the ST7MC starter kit hardware.
4.3.4.1 Push button reading
The function ‘BOOL key_scan(void)’ returns a boolean, TRUE if the push button (connected
to PC0) has been pushed during a minimum duration. This duration can be programmed in
ms, to debounce the button reading. This timing is verified using ‘it_ST7MC.c’ module re-
sources, in ‘void TIMB_Interrupt(void)’ interrupt routine.
The location of the push button (port and bit location) must be specified at the beginning of the
ports.c file. The push button must be connected between ground and a pull-up resistor to get
a low level on the input pin when it is pushed (refer to ST7MC starter kit schematics for de-
tails).
4.3.4.2 LEDs
A set of functions can be called to switch ON, OFF or toggle the two LEDs present on the
starter kit: PORTS_RedLedOn, PORTS_RedLedOff, PORTS_RedLedToggle, etc. It must
be remembered that these two LEDs are powered using a single I/O (see schematics for de-
tails). Consequently:
– they cannot be turned ON simultaneously
– the I/O port state can be configured either as an output or as a floating input to switch OFF
the LEDs.
4.3.5 spi.c
This module contains the code related to the SPI peripheral. The initialization of this peripheral
is made within the ‘void SPI_Init(void)’ function. Care should be taken when configuring the
SPI interface in accordance with the system (particularly operating frequency and polarity).
Communication with a serial EEPROM can be done using the ‘Send_EEPROM(u8 address,
u8 data)’ and ‘Read_EEPROM(u8 address)’ routines.
47/77

Related parts for AN1905