![Silicon Laboratories Si4012 Скачать руководство пользователя страница 23](http://html1.mh-extra.com/html/silicon-laboratories/si4012/si4012_programming-manual_1272046023.webp)
AN746
Rev. 0.1
23
5.3.3. SPI Driver
The SPI related source files, called
spi.h and spi.c
, can be found in the /src/driver/ folder. To enable the SPI
interface the SPI port has to be enabled and associated to the crossbar. The directions of the SCK, MISO and
MOSI ports have to be configured properly on the IO port. Finally, the default states of the pins have to be set
correctly. Since several devices can be connected to the same SPI bus, the NSEL pin of the selected device is
activated during communication. Since the commands to be sent to the API are sequences of bytes, the module
has to be able to send and receive continuous byte stream. There are some cases when either reading a single
byte directly from the MISO or writing specified number of bits directly to the MOSI is necessary. In order to cover
these kinds of cases, “bitbang” read/write methods have been also implemented.
5.3.4. Timer Peripheral Driver
The timer related source files, called
timer.h
and
timer.c
, can be found in
the /src/drivers/
folder. The module
handles two 16-bit timers, timer2 and timer3. The most accurate timing interval can be calculated from the
frequency of the system clock which is generally 24.5 MHz. External clock sources can be selected as timer input
and moreover the required timing frequency can be adjusted thoroughly with several different prescalers. In
general, the timer settings belonging to the so-called heart-beat frequency of 1 kHz (1 ms) are prepared. Using the
timer with the 1 ms settings, timeouts multiple of 1 ms can be easily implemented. Timer related operations can
give possibilities to start or stop counting. Additionally, interrupts can be generated when the low byte of the timer
overflows. Timers can also be checked whether get expired or not.
U8
bSpi_ReadWriteSpi1
(
U8
biDataIn);
void
vSpi_EnableSpi1
(
void
);
void
vSpi_DisableSpi1
(
void
);
void
vSpi_ClearNselSpi1
(
U8
biSelectDevice);
void
vSpi_SetNselSpi1
(
U8
biSelectDevice);
void
vSpi_WriteDataSpi1
(
U8
biDataInLength,
U8
*pabiDataIn);
void
vSpi_ReadDataSpi1
(
U8
biDataOutLength,
U8
*paboDataOut);
U8
bSpi_ReadByteBitbangSpi1
(
void
);
void
vSpi_WriteBitsBitbangSpi1
(
U8
biDataIn,
U8
biNumOfBits);
void
vTmr_InitTmr2
(
void
);
void
vTmr_StartTmr2
(
U8
biPrescaler,
U16
wiPeriod,
U8
biItEnable,
U8
biExtClkSel);
BIT
gTmr_Tmr2Expired
(
void
);
void
vTmr_StartTmr3
(
U8
biPrescaler,
U16
wiPeriod,
U8
biItEnable,
U8
biExtClkSel);
UU16
wwTmr_GetTmr3
(
void
);
BIT
gTmr_Tmr3Expired
(
void
);
Содержание Si4012
Страница 14: ...AN746 14 Rev 0 1...
Страница 18: ...AN746 18 Rev 0 1...
Страница 29: ...AN746 Rev 0 1 29 NOTES...