32 Bit Peripheral Library Guide
32 Bit Peripheral Library Guide
Advanced
PIC32MX FAMILY
-page 2
Advanced
PIC32MX FAMILY
TABLE OF CONTENTS
1.0
2.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
11.0
12.0
13.0
14.0
15.0
16.0
17.0
19.1
18.0
19.0
20.0
21.0
Introduction................................................................................................................................................................................... 1
System Functions......................................................................................................................................................................... 3
Pcache Functions......................................................................................................................................................................... 7
DMA Functions........................................................................................................................................................................... 17
Bus Matrix Functions.................................................................................................................................................................. 53
NVM Functions........................................................................................................................................................................... 57
Reset Functions ......................................................................................................................................................................... 59
Interrupt Functions ..................................................................................................................................................................... 69
Oscillator Functions.................................................................................................................................................................... 91
Power Save Functions ............................................................................................................................................................... 97
I/O Port library ............................................................................................................................................................................ 99
Timer Functions........................................................................................................................................................................ 153
Input Capture Functions ........................................................................................................................................................... 175
Output Compare Functions ...................................................................................................................................................... 183
SPI Functions ........................................................................................................................................................................... 193
I2C Functions........................................................................................................................................................................ 215
UART Functions ....................................................................................................................................................................... 231
PMP Functions ......................................................................................................................................................................... 243
RTCC Functions....................................................................................................................................................................... 263
ADC10 Functions ..................................................................................................................................................................... 291
Comparator Functions.............................................................................................................................................................. 301
CVREF Functions..................................................................................................................................................................... 305
WDT Functions......................................................................................................................................................................... 309
Advanced
-page 1
PIC32MX FAMILY
-page 2
Advanced
INTRODUCTION
This chapter documents the functions and macros contained in the 32-bit
peripheral libraries. Examples of use are also provided.
1.1
C Code Applications
1.2
Chapter Organization
-page 1
Applications wishing to use peripheral libraries need to include <plib.h> file in their source file.
The C32 compiler has built-in knowledge of all header file and library files.
The master header file plib.h, includes all individual peripheral header files. An application needs
to include plib.h only to access any of the supported functions and macros. If you need to refer
to individual header file content, they are located in pic32mx\include\peripheral folder in your C32
installation directory. Complete source is located in pic32-libs\peripheral folder.
If required, you may rebuild the peripheral libraries. Please follow the procedure outlined in the
text file located in the pic32-libs directory.
-page 2
2.0
SYSTEM FUNCTIONS
The PIC32MX system library consists of functions and macros to perform system level operations.
SYSTEMConfigPerformance
SYSTEMConfigWaitStatesAndPB
SYSTEMConfigPB
Advanced - CONFIDENTIAL
062507-page 3
SYSTEM Functions
SYSTEMConfigPerformance
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
This function configures the Flash Wait States, Data Wait States and
PBCLK divider to lowest value allowed for the given system clock. If the
device has Prefetch-Cache module, it also enables prefetch and cache
mode. In summary, this function configures all necessary parameters to
achieve maximum performance for given system clock
Code Example:
SYSTEMConfigPerformance(72000000);
SYSTEMConfigWaitStatesAndPB
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
This function configures flash wait states and PBCLK divider to lowest
value allowed for the given system clock. It does not configure prefetch
cache module.
Source File:
Code Example:
SYSTEMConfigWaitStatesAndPB(72000000);
SYSTEMConfigPB
062507-page 4
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Advanced - CONFIDENTIAL
SYSTEMConfigPB
Remarks:
This function configures the PBCLK divider to lowest value allowed for
the given system clock.
Source File:
Code Example:
SYSTEMConfigPB(72000000);
Advanced - CONFIDENTIAL
062507-page 5
The following code example illustrates how to configure the device for maximum performance for
a given system clock.
#include <plib.h>
// Configuration Bit settings
// SYSCLK = 72 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 36 MHz
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
// WDT OFF
// Other options are don't care
//
#pragma config FPLLMUL = MUL_18, FPLLIDIV = DIV_2
#pragma FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
int main(void)
{
/*
Configure the device for maximum performance.
This macro sets flash wait states, PBCLK divider and DRM wait states
based on the specified lock frequency. It also turns on the cache mode
if avaialble.
Based on the current frequency, the PBCLK divider will be set at 1:2.
This knoweldge is required to correctly set UART baud rate, timer
reload value and other time sensitive setting.
*/
SYSTEMConfigPerformance(72000000L);
// Use PBCLK divider of 1:2 to calculate UART baud, timer tick etc.
...
}
062507-page 6
Advanced - CONFIDENTIAL
2.0
PCACHE FUNCTIONS
The PIC32MX Pcache library consists of functions and macros supporting common configuration
and control features of this peripheral set.
PrefetchCache Operations
cheConfigure
mCheConfigure
mCheGetCon
mCheSetCacheAccessLine
mCheGetAcc
mCheSetCacheTag
mCheGetCacheTag
mCheSetMask
mCheGetMask
mCheWriteCacheLine
mCheInvalidateLine
mCheInvalidateAllLines
mCheLockLine
mCheGetHit
mCheGetMis
CheKseg0CacheOff
CheKseg0CacheOn
-page 7
cheConfigure
Description:
Include:
plib.h
Prototype:
Arguments:
checoh
dcsz
prefen
pfmws
Return Value:
None
Remarks:
Code Example:
mCheConfigure
Description:
Include:
plib.h
Prototype:
void mCheConfigure(config);
Arguments:
config
-page 8
mCheConfigure (Continued)
Flash Wait States
CHE_CONF_WS0
CHE_CONF_WS1
CHE_CONF_WS2
CHE_CONF_WS3
CHE_CONF_WS4
CHE_CONF_WS5
CHE_CONF_WS6
CHE_CONF_WS7
(These bit fields are mutually exclusive)
Return Value:
None
Remarks:
Code Example:
mCheConfigure(CHE_CONF_PF_C | CHE_CONF_WS2);
mCheGetCon
Description:
Include:
plib.h
Prototype:
void mCheGetCon(void);
Arguments:
None
Return Value:
Remarks:
Code Example:
mCheSetCacheAccessLine
Description:
This macro is used to set up the CHEACC register. The value of the
CHEACC register is used as an index during any access to cache line
information such as tags, masks, or data words.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
Code Example:
mCheSetCacheAccessLine(12,1);
-page 9
Include:
plib.h
Prototype:
void mCheGetAcc(void);
Arguments:
None
Return Value:
Remarks:
Code Example:
mCheSetCacheTag
Description:
This macro writes a tag entry into a single line of the prefetch cache.
Include:
plib.h
Prototype:
Arguments:
lineno
addr
attr
Line Valid
CHE_TAG_INVALID
CHE_TAG_VALID
(These bit fields are mutually exclusive)
Line Locked
CHE_TAG_UNLOCKED
CHE_TAG_LOCKED
(These bit fields are mutually exclusive)
Line Type
CHE_TAG_TYPE_DATA
CHE_TAG_TYPE_INST
(These bit fields are mutually exclusive)
Return Value:
None
Remarks:
The macro sets the tag bits of a single cache line. The cache line
corresponding to the lineno parameter is selected automatically by a
call to the mCheSetCacheAccessLine macro.
This function must be used carefully. Setting a tag to
CHE_TAG_VALID without calling mCheWriteCacheLine() can cause
unpredictable results.
Code Example:
-page 10
mCheGetCacheTag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
Code Example:
tag0 = mCheGetCacheTag(0);
mCheSetMask
Description:
This macro writes a mask entry into a single line of the prefetch cache.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
The macro sets the mask bits of a single cache line. The cache line
corresponding to the idx parameter is selected automatically by a call to
the mCheSetCacheAccessLine macro.
This function must be used carefully. Setting a mask value to non-zero
causes tag bits to be ignored during cache lookup operations whenever
instruction fetches or data reads from the program flash memory occur.
Note: Only cache lines 10 and 11 have CHEMSK registers.
Code Example:
mCheSetMask(10, 0x40);
-page 11
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
Code Example:
curmask10 = mCheGetMask(10);
mCheWriteCacheLine
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
Unlike most of the other functions that write to a cache line, this macro
does not automatically select a cache line by calling
mCheSetCacheAccessLine().
mCheSetCacheAccessLine() must be called before using this macro
Code Example:
-page 12
mCheSetCacheAccessLine(12,1);
mCheWriteCacheLine(val_array);
mCheInvalidateLine
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
The macro clears the valid bit in the tag of a single cache line. The
cache line corresponding to the idx parameter is selected automatically
by a call to the mCheSetCacheAccessLine macro.
Code Example:
mCheInvalidateLine(5);
mCheInvalidateAllLines
Description:
This macro invalidates all the lines located in the prefetch cache
Include:
plib.h
Prototype:
void mCheInvalidateAllLines(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mCheInvalidateAllLines();
mCheLockLine
Description:
This macro causes an automatic fetch and lock of a single cache line.
Include:
plib.h
Prototype:
Arguments:
idx
type
addr
Return Value:
None
Remarks:
The macro clears the valid bit and sets the lock bit in the tag of a single
cache line. The cache line corresponding to the idx parameter is
selected automatically by a call to the mCheSetCacheTag macro.
A cache line marked as locked and not valid will cause the data at the
corresponding address to be fetched and locked in the prefetch cache.
Code Example:
mCheLockLine(3, 1, 0x1d0030a0);
-page 13
Include:
plib.h
Prototype:
void mCheGetHit(void);
Arguments:
None
Return Value:
Remarks:
Code Example:
mCheGetCon();
mCheGetMis
Description:
Include:
plib.h
Prototype:
void mCheGetCon(void);
Arguments:
None
Return Value:
Remarks:
Code Example:
mCheGetCon();
CheKseg0CacheOff
-page 14
Description:
Include:
plib.h
Prototype:
void CheKseg0CacheOff(void);
Arguments:
None
Return Value:
None
Remarks:
This function writes the value 2 to the CCA bits in the Config register
thereby disabling the cache for code executing within the KSEG0
memory region.
Code Example:
CheKseg0CacheOff();
CheKseg0CacheOn
Description:
Include:
plib.h
Prototype:
void CheKseg0CacheOn(void);
Arguments:
None
Return Value:
None
Remarks:
This function writes the value 3 to the CCA bits in the Config register
thereby enabling the cache for code executing within the KSEG0
memory region.
Source File:
Code Example:
CheKseg0CacheOn();
-page 15
#include <plib.h>
int main(void)
{
// Set Periph Bus Divider 72MHz / 2 = 36MHz Fpb
mOSCSetPBDIV( OSC_PB_DIV_2 );
// enable cacheability for KSEG0
CheKseg0CacheOn();
// configure the cache for prefetch and 2 wait-state operation
mCheConfigure(CHE_CONF_WS2 | CHE_CONF_PF_C);
// The prefetch cache is now configured and ready for use
...
return 0;
}
-page 16
3.0
DMA FUNCTIONS
This section provides a list and a description of the interface functions that are part of the DMA
API Peripheral Library.
3.1
DmaChnOpen
Description:
The function configures the selected DMA channel using the supplied
user flags and priority.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
This is a high level access function that doesn't give access to all the
settings possible for a DMA channel. Use the low level functions to
address special settings.
After calling this function, the channel should be enabled using
DmaChnEnable(chn) call.
If the CRC engine is attached to the submitted channel, the CRC
append mode will be turned off. This way, the transfer will occur
correctly together with CRC calculation.
The start and abort Irqs will be disabled and the channel event enable
flags are disabled. User has to call normal channel functions to enable
the event flags if needed.
Source File:
dma_chn_open_lib.c
Code Example:
DmaChnOpen(3, DMA_CHN_PRI2,
DMA_OPEN_EXT|DMA_OPEN_AUTO|DMA_OPEN_MATCH);
DmaChnEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
-page 17
Source File:
dma_chn_enable_lib.c
Code Example:
DmaChnEnable(3);
DmaChnDisable
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
Source File:
dma_chn_disable_lib.c
Code Example:
DmaChnDisable(3);
DmaChnSetTxfer
Description:
The function sets the transfer characteristics for a normal (i.e. not
extended) DMA channel transfer:
- the source and the destination addresses.
- the source and destination lengths
- and the number of bytes transferred per event..
Include:
plib.h
Prototype:
Arguments:
-page 18
Return Value:
None
Remarks:
None
Source File:
dma_chn_set_txfer_lib.c
Code Example:
DmaChnSetExtTxfer
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_set_ext_txfer_lib.c
Code Example:
DmaChnSetMatchPattern
Description:
The function sets the curent match pattern for the selected DMA
channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_set_match_pattern_lib.c
Code Example:
DmaChnSetMatchPattern(3, '\r');
DmaChnGetMatchPattern
Description:
The function retrieves the curent match pattern for the selected DMA
channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
dma_chn_get_match_pattern_lib.c
Code Example:
int stopPattern=DmaChnGetMatchPattern(3);
-page 19
The function enables the channel and initiates (forces) a DMA transfer
for the selected DMA channel. If waiting for the transfer completion
needed (user doesn't use an ISR to catch this event) the function will
periodically query the DMA controller for the transfer completion status.
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
Source File:
dma_chn_start_txfer_lib.c
Code Example:
DmaChnForceTxfer
-page 20
Description:
The function forces a DMA transfer to occur for the selected DMA
channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_force_txfer_lib.c
Code Example:
DmaChnForceTxfer(2);
DmaChnAbortTxfer
Description:
The function aborts a current undergoing DMA transfer for the selected
DMA channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_abort_txfer_lib.c
Code Example:
DmaChnAbortTxfer(2);
3.2
DmaChnSetEvEnableFlags
Description:
The function sets the event enable flags for the selected DMA channel.
Multiple flags can be orr-ed together. Any flag that is set in the eFlags
will be enabled for the selected channel, the other channel event flags
won't be touched.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_set_ev_enable_flags_lib.c
Code Example:
DmaChnSetEvEnableFlags(3,
DMA_EV_ERR|DMA_EV_ABORT|DMA_EV_BLOCK_DONE|DMA_EV_SRC
_FULL);
-page 21
The function clears the event enable flags for the selected DMA
channel. Multiple flags can be orr-ed together. Any flag that is set in the
eFlags will be enabled for the selected channel, the other channel
event flags won't be touched.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
dma_chn_clr_ev_enable_flags_lib.c
Code Example:
DmaChnClrEvEnableFlags(3,
DMA_EV_ERR|DMA_EV_ABORT|DMA_EV_BLOCK_DONE|DMA_EV_SRC
_FULL);
DmaChnWriteEvEnableFlags
Description:
The function sets the event enable flags for the selected DMA channel.
The channel event flags are forced to the eFlags value.
Include:
plib.h
Prototype:
Arguments:
-page 22
DmaChnWriteEvEnableFlags
DMA_EV_SRC_HALF: source half event
DMA_EV_SRC_FULL: source full event
DMA_EV_ALL_EVNTS: all of the above flags
Return Value:
None
Remarks:
None
Source File:
dma_chn_write_ev_enable_flags_lib.c
Code Example:
DmaChnWriteEvEnableFlags(3, DMA_EV_ALL_EVNTS);
DmaChnGetEvEnableFlags
Description:
The function returns the event enabled flags for the selected DMA
channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
dma_chn_get_ev_enable_flags_lib.c
Code Example:
DmaEvFlags enabledFlags=DmaChnGetEvEnableFlags(3);
DmaChnClrEvFlags
Description:
The function clears the event flags for the selected DMA channel.
Multiple flags can be orr-ed together. Any flag that is set in the eFlags
will be cleared for the selected channel, the other channel event flags
won't be touched.
Include:
plib.h
Prototype:
Arguments:
-page 23
None
Remarks:
None
Source File:
dma_chn_clr_ev_flags_lib.c
Code Example:
DmaChnClrEvFlags(3, DMA_EV_ALL_EVNTS);
DmaChnGetEvFlags
Description:
The function returns the current event flags for the selected DMA
channel.
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
dma_chn_get_ev_flags_lib.c
Code Example:
DmaEvFlags enabledFlags=DmaChnGetEvFlags(3);
DmaChnIntEnable
mDmaChnIntEnable
Description:
-page 24
DmaChnIntEnable
mDmaChnIntEnable
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
DmaChnIntDisable
mDmaChnIntDisable
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
DmaChnGetIntEnable
mDmaChnGetIntEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
plib.h
Code Example:
-page 25
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
DmaChnGetIntPriority
mDmaChnGetIntPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
DmaChnGetIntSubPriority
mDmaChnGetIntSubPriority
-page 26
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
DmaChnGetIntSubPriority
mDmaChnGetIntSubPriority
Code Example:
DmaChnGetIntFlag
mDmaChnGetIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
plib.h
Code Example:
DmaChnClrIntFlag
mDmaChnClrIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
3.3
-page 27
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
Source File:
dma_chn_memcpy_lib.c
Code Example:
DmaChnStrcpy
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
-page 28
DmaChnStrcpy
The channel will operate in extended mode and will support transfers of
up to 64K bytes.
The start and abort Irqs will be disabled and the channel event enable
flags, are disabled. User has to call normal channel functions to enable
the event flags if needed.
Multiple channels could be opened to perform fast memory transfers, if
necessary.
Return Value:
Source File:
dma_chn_strcpy_lib.c
Code Example:
DmaChnStrncpy
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
-page 29
dma_chn_strncpy_lib.c
Code Example:
DmaChnMemCrc
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
Source File:
dma_chn_mem_crc_lib.c
Code Example:
3.4
-page 30
mCrcConfigure
Description:
The macro configures the CRC module by setting the parameters that
define the generator polynomial:
- the length of the CRC generator polynomial, pLen;
- the macro sets the layout of the shift stages that take place in the CRC
generation.
Setting a bit to 1 enables the XOR input from the MSb (pLen bit) to the
selected stage in the shift register. If bit is cleared, the selected shift
stage gets data directly from the previous stage in the shift register.
Note that in a proper CRC polynomial, both the most significant bit
(MSb) and least significant bit(LSb) are always a '1'. Considering the
generator polynomial: X^16+X^15+X^2+1, the value to be written as
feedback should be 0x8005, or 0x8004, but not 0x018005;
- the macro sets the seed of the CRC generator. This is the initial data
present in the CRC shift register before the CRC calculation begins. A
good initial value is usually 0xffffffff.
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
CrcAttachChannel
Description:
Include:
plib.h
Prototype:
Arguments:
-page 31
None
Return Value:
None
Source File:
dma_crc_attach_channel_lib.c
Code Example:
CrcAttachChannel(0, 1);
CrcResult
Description:
Include:
plib.h
Prototype:
int CrcResult(void);
Arguments:
None
Remarks:
The function returns the valid CRC result by masking out the unused
MSbits in the CRC register. Use CrcGetValue() to get the full CRC
register value.
Return Value:
Source File:
dma_crc_result_lib.c
Code Example:
int myCrc=CrcResult();
3.5
mDmaEnable
-page 32
Description:
Include:
plib.h
Prototype:
void mDmaEnable(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
dma.h
Code Example:
mDmaEnable();
mDmaDisable
Description:
Include:
plib.h
Prototype:
void mDmaDisable(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
dma.h
Code Example:
mDmaDisable();
mDmaReset
Description:
Include:
plib.h
Prototype:
void mDmaReset(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
dma.h
Code Example:
mDmaReset();
mDmaSuspend
Description:
The macro suspends the DMA controller activity. The activity can be
later on resumed with mDmaResume();
Include:
plib.h
Prototype:
void mDmaSuspend(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
dma.h
Code Example:
mDmaSuspend();
DmaGetStatus
Description:
The function updates the info for the current DMA controller status. It
updates the last DMA: operation, channel used and address.
Include:
plib.h
Prototype:
Arguments:
-page 33
None
Remarks:
None
Source File:
dma_get_status_lib.c
Code Example:
mDmaSetGlobalFlags
Description:
The macro affects the global behavior of the DMA controller. It sets the
specified flags. Any flag that is set in the gFlags will be enabled, the
other flags won't be touched.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mDmaSetGlobalFlags(DMA_GFLG_SIDL|DMA_GFLG_ON);
mDmaClrGlobalFlags
Description:
The macro affects the global behavior of the DMA controller. It clears
the specified flags. Any flag that is set in the gFlags will be enabled, the
other flags won't be touched.
Include:
plib.h
Prototype:
Arguments:
-page 34
mDmaClrGlobalFlags
- DMA_GFLG_FRZ: DMA controller
frozen/active in debug mode
- DMA_GFLG_ON: DMA controller
enabled/desabled
- DMA_GFLG_ALL_FLAGS: all of the above
flags
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mDmaClrGlobalFlags(DMA_GFLG_SIDL|DMA_GFLG_ON);
mDmaWriteGlobalFlags
Description:
The macro affects the global behavior of the DMA controller.It forces
the flags to have the specified gFlags value.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mDmaWriteGlobalFlags(DMA_GFLG_ALL_FLAGS);
mDmaGetGlobalFlags
Description:
Include:
plib.h
Prototype:
DmaGlblFlags mDmaGetGlobalFlags(void);
Arguments:
None
Remarks:
None
Return Value:
-page 35
dma.h
Code Example:
DmaGlblFlags dmaFlags=mDmaGetGlobalFlags();
3.6
DmaChnGetSrcPnt
Description:
The function retrieves the current source pointer for the selected DMA
channel. In normal mode it is the current offset, 0-255, in the source
transfer buffer.
Include:
plib.h
Prototype:
Arguments:
Remarks:
This function is intended for use in normal mode. In the extended mode
the source and destination pointers are concatenated into a 16 bit
register. Use DmaChnGetDstPnt() instead.
Return Value:
Source File:
dma_chn_get_src_pnt_lib.c
Code Example:
int srcPnt=DmaChnGetSrcPnt(3);
DmaChnGetDstPnt
-page 36
Description:
The function retrieves the current destination pointer for the selected
DMA channel. In normal mode it is the current offset, 0-255, in the
destination transfer buffer. In extended mode the function retrieves the
current progress buffer pointer, ranging 0-65535.
Include:
plib.h
Prototype:
Arguments:
Remarks:
This function is intended for use in both normal and extended mode. In
the extended mode the source and destination pointers are
concatenated into a 16 bit register.
Return Value:
Source File:
dma_chn_get_dst_pnt_lib.c
Code Example:
int dstPnt=DmaChnGetDstPnt(3);
DmaChnGetCellPnt
Description:
The function retrieves the current transfer progress pointer for the
selected DMA channel. In normal mode it ranges 0-255.
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
Source File:
dma_chn_get_cell_pnt_lib.c
Code Example:
int cellPnt=DmaChnGetCellPnt(3);
3.7
DmaChnSetEventControl
Description:
The function sets the events that start and abort the transfer for the
selected DMA channel.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma_chn_set_event_control_lib.c
Code Example:
DmaChnSetEventControl(3,
DMA_EV_START_IRQ_EN|DMA_EV_MATCH_EN|DMA_EV_START_IRQ
(_UART2_RX_IRQ));
DmaEvCtrl evCtrl; evCtrl.w=0; evCtrl.abortIrqEn=1;
evCtrl.matchEn=1; evCtrl.startIrq=_UART2_RX_IRQ;
DmaChnSetEventControl(3, evCtrl.w);
-page 37
The function retrieves the events that start and abort the transfer for the
selected DMA channel.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
dma_chn_get_event_control_lib.c
Code Example:
int evCtrlW=DmaChnGetEventControl(3);
if(evCtrlW&DMA_EV_MATCH_EN) {...}
DmaEvCtrl evCtrl; evCtrl.w=DmaChnGetEventControl(3);
if(evCtrl.matchEn){...}
DmaChnSetControl
Description:
The function enables/disables the selected DMA channel and also sets
the channel priority, chaining mode, auto or extended mode and events
detection.
Include:
plib.h
Prototype:
Arguments:
Remarks:
-page 38
None
DmaChnSetControl
Return Value:
None
Source File:
dma_chn_set_control_lib.c
Code Example:
DmaChnSetControl(3,
DMA_CTL_PRI(DMA_CHN_PRI2)|DMA_CTL_AUTO_EN|DMA_CTL_CH
AIN_EN);
DmaChnCtrl chCtrl; chCtrl.w=0;
chCtrl.chPri=DMA_CHN_PRI2; chCtrl.autoEn=1;
chCtrl.chainEn=1; DmaChnSetControl(3, chCtrl.w);
DmaChnGetControl
Description:
The function retrieves the current control settings for the selected DMA
channel, including the channel enable/disable status, the channel
priority, chaining mode, auto or extended mode and events detection.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
dma_chn_get_control_lib.c
Code Example:
DmaChnGetEvDetect
Description:
The function returns the current event detection setting for the selected
DMA channel.
Include:
plib.h
Prototype:
Arguments:
-page 39
None
Return Value:
Source File:
dma_chn_get_ev_detect_lib.c
Code Example:
int evDetect=DmaChnGetEvDetect(3);
DmaChnGetTxfer
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Noner
Source File:
dma_chn_get_txfer_lib.c
Code Example:
3.8
mCrcEnable
Description:
-page 40
The macro enables the CRC module functionality and the attached
DMA channel transfers are routed to the CRC module.
mCrcEnable
Include:
plib.h
Prototype:
void mCrcEnable(void);
Arguments:
None
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mCrcEnable();
mCrcDisable
Description:
Include:
plib.h
Prototype:
void mCrcDisable(void);
Arguments:
None
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mCrcDisable();
mCrcGetEnable
Description:
Include:
plib.h
Prototype:
int mCrcGetEnable(void);
Arguments:
None
Remarks:
None
Return Value:
Source File:
dma.h
Code Example:
int isCrcEnabled=mCrcGetEnable();
mCrcAppendModeEnable
Description:
The macro enables the CRC append mode. In this mode, the attached
DMA channel reads the source data but does not write it to the
destination address. The data it's just passed to the CRC generator for
CRC calculation. When the block transfer is completed, the CRC result
is written to the DMA channel destination address.
Include:
plib.h
Prototype:
void mCrcAppendModeEnable();
Arguments:
None
Remarks:
-page 41
None
Source File:
dma.h
Code Example:
mCrcAppendModeEnable();
mCrcAppendModeDisable
Description:
The macro disables the CRC append mode. When the append mode is
disabled, the attached DMA channel normally transfers data from
source to destination. Data is also passed to the CRC controller for
CRC calculation. When the DMA transfer is completed, the CRC value
is available using the CrcGetValue function.
Include:
plib.h
Prototype:
void mCrcAppendModeDisable();
Arguments:
None
Remarks:
None.
Return Value:
None
Source File:
dma.h
Code Example:
mCrcAppendModeDisable();
mCrcGetAppendMode
Description:
Include:
plib.h
Prototype:
int mCrcGetAppendMode(void);
Arguments:
None
Remarks:
None.
Return Value:
Source File:
dma.h
Code Example:
int isAppendEnabled=mCrcGetAppendMode();
mCrcSetDmaAttach
-page 42
Description:
The macro attaches a DMA channel to the CRC module. The DMA
channel transfers will be routed to the CRC module.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mCrcSetDmaAttach(3);
mCrcGetDmaAttach
Description:
The macro returns the DMA channel number that is currently attached
to the CRC module.
Include:
plib.h
Prototype:
int mCrcGetDmaAttach(void);
Arguments:
None
Remarks:
None
Return Value:
Source File:
dma.h
Code Example:
int chn=mCrcGetDmaAttach();
mCrcSetPLen
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mCrcSetPLen(16);
mCrcGetPLen
Description:
Include:
plib.h
Prototype:
int mCrcGetPLen(void);
Arguments:
None
Remarks:
None
Return Value:
Source File:
dma.h
Code Example:
int polyLen=mCrcGetPLen();
mCrcSetShiftFeedback
Description:
The macro sets the layout of the shift stages that take place in the CRC
generation. Setting a bit to 1 enables the XOR input from the MSb
(pLen bit) to the selected stage in the shift register. If bit is cleared, the
selected shift stage gets data directly from the previous stage in the
shift register.
-page 43
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
dma.h
Code Example:
mCrcSetShiftFeedback(0x8005);
mCrcGetShiftFeedback
Description:
The macro returns the layout of the shift stages that take place in the
CRC generation. A bit set to 1 enables the XOR input from the MSb
(pLen bit) to the selected stage in the shift register. If a bit is cleared,
the selected shift stage gets data directly from the previous stage in the
shift register.
Include:
plib.h
Prototype:
int mCrcGetShiftFeedback(void);
Arguments:
None
Remarks:
Return Value:
Source File:
dma.h
Code Example:
int feedback=mCrcGetShiftFeedback();
mCrcSetSeed
Description:
The macro sets the seed of the CRC generator. This is the initial data
present in the CRC shift register before the CRC calculation begins.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
dma.h
Code Example:
mCrcSetSeed(0xffff);
mCrcGetValue
-page 44
Description:
The macro returns the current value of the CRC shift register..
Include:
plib.h
Prototype:
int mCrcGetValue(void);
Arguments:
None
mCrcGetValue
Remarks:
Only the remainder bits (0 to pLen-1) are significant, the rest should be
ignored.
Return Value:
Source File:
dma.h
Code Example:
int calcCrc=mCrcGetValue()&0xffff;
3.9
DmaChnSetEvFlags
Description:
The function sets the event flags for the selected DMA channel.
Multiple flags can be orr-ed together. Any flag that is set in the eFlags
will be set for the selected channel, the other channel event flags won't
be touched.
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
dma_chn_set_ev_flags_lib.c
Code Example:
DmaChnSetEvFlags(0,
DMA_EV_ERR|DMA_EV_ABORT|DMA_EV_BLOCK_DONE|DMA_EV_SRC
_FULL);
DmaChnWriteEvFlags
Description:
The function writes the event flags for the selected DMA channel. The
channel event flags are forced to the eFlags value.
Include:
plib.h
Prototype:
Arguments:
-page 45
Return Value:
None
Source File:
dma_chn_write_ev_flags_lib.c
Code Example:
DmaChnWriteEvFlags(0,
DMA_EV_ERR|DMA_EV_ABORT|DMA_EV_BLOCK_DONE|DMA_EV_SRC
_FULL);
mDmaFreezeEnable
Description:
The macro sets the DMA controller behavior in Debug mode. The DMA
controller is frozen in Debug mode.
Include:
plib.h
Prototype:
void mDmaFreezeEnable();
Arguments:
None
Remarks:
Return Value:
None
Source File:
dma.h
Code Example:
mDmaFreezeEnable();
mDmaFreezeDisable
-page 46
Description:
The macro sets the DMA controller behavior in Debug mode. The DMA
controller continues to run in Debug mode.
Include:
plib.h
Prototype:
void mDmaFreezeDisable();
Arguments:
None
Remarks:
Return Value:
None
Source File:
dma.h
Code Example:
mDmaFreezeDisable();
3.10
DmaChnSetRegister
Description:
Include:
plib.h
Prototype:
Arguments:
-page 47
Return Value:
None
Source File:
dma_chn_set_register_lib.c
Code Example:
DmaChnGetRegister
Description:
Include:
plib.h
Prototype:
Arguments:
-page 48
Remarks:
Return Value:
Source File:
dma_chn_set_register_lib.c
Code Example:
3.11
Example of Use
-page 49
int main(void)
{
SYSTEMConfigWaitStatesAndPB(72000000L);
// configure the proper PB frequency and the number of wait states
CheKseg0CacheOn();// enable the cache for the best performance
mBMXSetArbMode(2);// arbitration mode 2, round-robin
// a memory to memory copy
#defineMIN_RAM_TXFER_SIZE8// min size per transfer
#defineMAX_RAM_TXFER_SIZE512// we test the extended mode when
// transfer more than 256 bytes
unsigned char*pDmaSrc;
unsigned char*pDmaDst;
unsigned inttxferSize;
DmaTxferRestxferRes;
DmaOpenFlagsoFlag; // DMA open flags
int
dmaOk=0;
int
matchOk=0;
int
allocOk=0; // operations ok flags
int
chn=3;
// DMA channel to use for our example
srand((int)__TIME__);// seed the pseudo random generator
txferSize=MIN_RAM_TXFER_SIZE
txferSize+=rand()%(MAX_RAM_TXFER_SIZE-MIN_RAM_TXFER_SIZE+1);
// get a random transfer size
oFlag=txferSize>256?DMA_OPEN_EXT:DMA_OPEN_NORM;
DmaChnOpen(chn, DMA_CHN_PRI2, oFlag);
// configure the DMA controller appropriately
pDmaSrc=(unsigned char*)malloc(txferSize);
pDmaDst=(unsigned char*)malloc(txferSize);
if(pDmaSrc && pDmaDst)
{
unsigned char*pS;
unsigned char*pD;
int
ix;
allocOk=1;
for(ix=0, pS=pDmaSrc; ix<txferSize; ix++)
{
*pS++=rand();// fill the source buffer
}
if(txferSize>256)
{
// extended mode transfer
// program the DMA channel source add, dest add, block size
DmaChnSetExtTxfer(chn, pDmaSrc, pDmaDst, txferSize);
}
else
{
// normal mode transfer
// program the DMA channel source add, dest add,
// source and dest size, cell size adjusted
-page 50
-page 51
-page 52
4.0
4.1
Individual Functions/Macros
mBMXSetArbMode
Description:
This macro sets the bus matrix arbitration mode in BMXCON register.
Include:
plib.h
Prototype:
mBMXSetArbMode(mode)
Arguments:
mode - mode = 0, 1 or 2
Return Value:
None
Remarks:
Code Example:
Example:
mBMXSetArbMode(1); //set arb mode to 1
mBMXEnableBreakExactDRM / mBMXDisableBreakExactDRM
Description:
Include:
plib.h
Prototype:
mBMXEnableBreakExactDRM(),
mBMXDisableBreakExactDRM()
Arguments:
None
Return Value:
None
Remarks:
Code Example:
Example:
mBMXEnableBreakExactDRM();
mBMXEnableXcpts / mBMXDisableXcpts
Description:
Include:
plib.h
Prototype:
mBMXEnableXcpts(val),
mBMXDisableXcpts(val)
Arguments:
Return Value:
None
Remarks:
Code Example:
Example:
mSetFlashPartition
Description:
-page 53
plib.h
Prototype:
mSetFlashUserPartition (USER_FLASH_PGM_SZ)
Arguments:
Return Value:
None
Remarks:
The macro initializes the Base Address registers for partinioning the on
chip Flash. The Flash memory is divided into two partitions. By default
the entire Flash is mapped to Kernel mode program space. If this
macro is called with a non-zero value, the total Flash size minus this
value (user mode program size) is assigned to the Kernel mode
program space in Flash.
Code Example:
Example:
mBMXSetFlashUserPartition(0x2000); //set user mode program
partition in flash to 8KBytes
mBMXSetRAMKernProgOffset
Description:
Include:
plib.h
Prototype:
mBMXSetRAMKernProgOffset (offset)
Arguments:
Return Value:
None
Remarks:
Code Example:
Example:
mBMXSetRAMUserDataOffset
Description:
Include:
plib.h
Prototype:
mBMXSetRAMUserDataOffset (offset)
Arguments:
Return Value:
None
Remarks:
For user mode data RAM, the BMXDUDBA must be set properly. This
macro initializes this register.
Code Example:
Example:
mBMXSetRAMUserProgOffset
-page 54
Description:
Include:
plib.h
2007 Microchip Technology Inc.
mBMXSetRAMUserProgOffset
Prototype:
mBMXSetRAMUserProgOffset (offset)
Arguments:
offset - Offset into the RAM for start of usermode Program partition
Return Value:
None
Remarks:
To execute code from RAM in user mode, the BMXDUPBA must be set
properly. This macro initializes this register.
Code Example:
Example:
Include:
plib.h
Prototype:
mBMXEnableIxiExpt
mBMXDisableIxiExpt
mBMXEnableIcdExpt
mBMXDisableIcdExpt
mBMXEnableDmaExpt
mBMXDisableDmaExpt
mBMXEnableCpuDExpt
mBMXDisableCpuDExpt
mBMXEnableCpuIExpt
mBMXDisableCpuIExpt
mBMXEnablePfmCheDma
mBMXDisablePfmCheDma
Arguments:
None
Return Value:
None
Remarks:
These macros let the programmer change individual bits for exception
generation in the bus matrix config BMXCON register. This method
allows the programmer to change the required bit without effecting the
rest of the configuration bits.
Code Example:
...
...
mBMXEnableDmaExpt();
address exceptions
...
...
ShutDown:
...
...
-page 55
-page 56
5.0
NVM FUNCTIONS
This section contains a list of individual functions for NVM and an example of use of the functions.
5.1
Individual Functions
NVMProgram
Description:
This function programs size characters from the source buffer to Flash
memory starting at the destination address.
Include:
plib.h
Prototype:
Arguments:
*address
*data
size
Remarks:
None
Code Example:
NVMErasePage
Description:
Include:
plib.h
Prototype:
Arguments:
*address
Return Value
Remarks:
None
Code Example:
NVMErasePage((void*) 0xBD000000);
NVMWriteRow
Description:
Include:
plib.h
Prototype:
Arguments:
*address
*data
Return Value
Remarks:
None
Code Example:
NVMWriteWord
Description:
Include:
plib.h
-page 57
Arguments:
*address
data
Return Value
Remarks:
None
Code Example:
NVMClearError
Description:
This function clears the error flag and resets the flash controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value
Remarks:
None
Code Example:
NMVClearError();
NVMIsError
-page 58
Description:
This function checks the error flags and return there value.
Include:
plib.h
Prototype:
NVMIsError()
Arguments:
None
Return Value
Remarks:
None
Code Example:
if(NVMIsError()) NVMClearError();
6.0
RESET FUNCTIONS
The PIC32MX Reset library consists of functions and macros supporting common control features of this peripheral.
Get Status Flag Operations
mGetPORFlag
mGetBORFlag
mGetMCLRFlag
mGetCMRFlag
mGetWDTRFlag
mGetSWRFlag
mGetSleepFlag
mGetIdleFlag
mGetVregFlag
Clear/Set Status Flag Operations
mClearPORFlag
mClearBORFlag
mClearMCLRFlag
mClearCMRFlag
mClearWDTRFlag
mClearSWRFlag
mClearSleepFlag
mClearIdleFlag
mClearVregFlag
mSetVregFlag
PIC30F, PIC24H and PIC33F compatible operations
PORStatReset
BORStatReset
isMCLR
isPOR
isBOR
isWU
isWDTTO
isWDTWU
-page 59
mGetPORFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetBORFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetMCLRFlag
Description:
This function checks if Reset condition is due to MCLR pin going low.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
-page 60
mGetSWRFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetWDTOFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetCMRFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
-page 61
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetIDLEFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mGetVREGSFlag
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
-page 62
6.2
mClearPORFlag
Description:
Include:
plib.h
Prototype:
mClearPORFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearPORFlag();
mClearBORFlag
Description:
This function clears BOR (brown out reset) status flag bit.
Include:
plib.h
Prototype:
mClearBORFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearBORFlag();
mClearMCLRFlag
Description:
Include:
plib.h
Prototype:
mClearMCLRFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearMCLRFlag();
-page 63
Include:
plib.h
Prototype:
mClearSWRFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearSWRFlag();
mClearWDTOFlag
Description:
This function clears WDTO (watch dog timeout) status flag bit.
Include:
plib.h
Prototype:
mClearWDTOFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearWDTOFlag();
mClearCMRFlag
Description:
Include:
plib.h
Prototype:
mClearCMRFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearCMRFlag();
mClearSLEEPFlag
Description:
Include:
plib.h
Prototype:
mClearSSLEEPFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
-page 64
mClearSLEEPFlag();
mClearIDLEFlag
Description:
Include:
plib.h
Prototype:
mClearIdleFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearIDLEFlag();
mClearVREGSFlag
Description:
Include:
plib.h
Prototype:
mClearVREGSFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mClearVREGSFlag();
mSetVREGSFlag
Description:
Include:
plib.h
Prototype:
mSetVREGSFlag(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
mSetVREGSFlag();
-page 65
isWDTTO
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
isWDTWU
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
Code Example:
-page 66
isWU
Description:
Include:
plib.h
Prototype:
char isWU(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
reset_is_wu.c
Code Example:
char reset_state;
reset_state = isWU();
PORStatReset
Description:
Include:
plib.h
Arguments:
None
Remarks:
None
Code Example:
PORStatReset;
BORStatReset
Description:
Include:
plib.h
Arguments:
None
Remarks:
None
Code Example:
BORStatReset;
-page 67
-page 68
7.0
INTERRUPT FUNCTIONS
7.1
System Functions
INTEnableSystemMultiVectoredInt
Description:
Include:
plib.h
Prototype:
void INTEnableSystemMultiVectoredInt(void)
Arguments:
none.
Return Value
None
Remarks:
User must call this function before any interrupts will be handled. The
interrupts will got to the assigned vector location.
Source File:
Code Example:
INTEnableSystemMultiVectoredInt();
INTEnableSystemSingleVectoredInt
Description:
Include:
plib.h
Prototype:
void INTEnableSystemSingleVectoredInt(void)
Arguments:
none.
Return Value
None
Remarks:
User must call this function before any interrupts will be handled. The
interrupts will got to a single vector location.
Source File:
Code Example:
INTEnableSystemSingleVectoredInt();
INTDisableInterrupts
Description:
Include:
plib.h
Prototype:
Arguments:
none.
Return Value
Remarks:
Source File:
Code Example:
INTEnableInterrupts
Description:
Include:
plib.h
Prototype:
void INTEnableInterrupts(void)
-page 69
none.
Return Value
Remarks:
Source File:
Code Example:
INTRestoreInterrupts
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
none
Remarks:
Source File:
Code Example:
INTGetPendingInterrupt
Description:
Include:
plib.h
Prototype:
Arguments:
none.
Return Value
Remarks:
The function will return the interrupt based on the natural priority. For
example, the core timer will be serviced before the UART 1 receiver
interrupt.
Source File:
Code Example:
-page 70
INTClearFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
none
Remarks:
This function will clear the interrupt flag of the passed value source.
See IRQ table for more information
Source File:
Code Example:
INTSetFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
none
Remarks:
This function will set the interrupt flag of the passed value source.
See IRQ table for more information
Source File:
Code Example:
INTGetFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
Remarks:
This function will get the interrupt flag of the passed value source.
See IRQ table for more information
Source File:
Code Example:
INTEnable
Description:
Include:
plib.h
-page 71
Arguments:
Return Value
none
Remarks:
This function will enable or disables the interrupt of the passed value
source. See IRQ table for more information
Source File:
Code Example:
INTGetEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
Remarks:
Source File:
Code Example:
INTSetPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
none
Remarks:
This function will set the interrupt priorityof interrupt the passed value
source. See IRQ table for more information
Source File:
Code Example:
INTGetPriority
-page 72
Description:
Include:
plib.h
INTGetPriority
Prototype:
Arguments:
Return Value
Remarks:
This function will get the interrupt priorityof interrupt the passed value
source. See IRQ table for more information
Source File:
Code Example:
INTSetSubPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
none
Remarks:
This function will set the interrupt sub-priority of interrupt the passed
value source. See IRQ table for more information
Source File:
Code Example:
INTGetSubPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
Remarks:
This function will get the sub-interrupt priorityof interrupt the passed
value source. See IRQ table for more information
Source File:
Code Example:
TABLE 8-1:
INTERRUPT ENUMERATIONS
Enumeration
Peripheral
INT_CT
INT_CS0
-page 73
INTERRUPT ENUMERATIONS
Enumeration
-page 74
Peripheral
INT_CS1
INT_INT0
External Interrupt 0
INT_T1
Timer 1 Interrupt
INT_IC1
INT_OC1
INT_INT1
External Interrupt 1
INT_T2
Timer 2 Interrupt
INT_IC2
INT_OC2
INT_INT2
External Interrupt 2
INT_T3
Timer 3 Interrupt
INT_IC3
INT_OC3
INT_INT3
External Interrupt 3
INT_T4
Timer 4 Interrupt
INT_IC4
INT_OC4
INT_INT4
External Interrupt 4
INT_T5
Timer 5 Interrupt
INT_IC5
INT_OC5
INT_CN
INT_SPI1E
SPI 1 Fault
INT_SPI1TX
INT_SPI1RX
INT_SPI1
SPI 1
INT_U1E
UART 1 Error
INT_U1RX
UART 1 Receiver
INT_U1TX
UART 1 Transmitter
INT_U1
UART 1
INT_I2C1B
INT_I2C1S
INT_I2C1M
INT_I2C1
I2C1
INT_AD1
INT_PMP
INT_CMP1
Comparator 1 Interrupt
INT_CMP2
Comparator 2 Interrupt
INT_SPI2E
SPI 2 Fault
INT_SPI2TX
INT_SPI2RX
INT_SPI2
SPI 2
INT_U2E
UART 2 Error
INT_U2RX
UART 2 Receiver
INT_U2TX
UART 2 Transmitter
TABLE 8-1:
INTERRUPT ENUMERATIONS
Enumeration
Peripheral
INT_U2
UART 2
INT_I2C2B
INT_I2C2S
INT_I2C2M
INT_I2C2
I2C2
INT_FSCM
INT_FCE
INT_RTCC
INT_DMA0
INT_DMA1
INT_DMA2
INT_DMA3
INT_DMA4
INT_DMA5
INT_DMA6
INT_DMA7
INT_USB
USB Interrupt
7.2
Inline Functions
INTGetInterruptVectorNumberAndPriority
Description:
This function gets the pending vector number and its prioirty.
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
None.
Source File:
None
Code Example:
7.3
System Macros
mClearIFSRegister
Description:
Include:
plib.h
Prototype:
void mClearIFSRegister(reg_num)
-page 75
Return Value
None
Remarks:
None.
Source File:
None
Code Example:
mClearIFSRegister(0);
mClearIECRegister
Description:
Include:
plib.h
Prototype:
void mClearIECRegister(reg_num)
Arguments:
Return Value
None
Remarks:
Set the edge that the external interrupt will generate an interrupt.
Source File:
None
Code Example:
mClearIECRegister(0);
mClearAllIFSRegister
Description:
This macro clears all the bits in all of the IFS registors
Include:
plib.h
Prototype:
void mClearAllIFSRegister(void)
Arguments:
None
Return Value
None
Remarks:
None..
Source File:
None
Code Example:
mClearAllIFSRegister();
mClearAllIECRegister
-page 76
Description:
This macro clears all the bits in all of the IEC registors
Include:
plib.h
Prototype:
void mClearAllIECRegister(void)
Arguments:
None
Return Value
None
Remarks:
None..
Source File:
None
Code Example:
mClearAllIECRegister();
mINTSetIFSx
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
The macro is for all IFS registors. If one would like to set bits in the
IFS1 register, they need to replace the x with 1
Source File:
None
Code Example:
mINTSetIFS0(1);
mINTSetIFS1(2);
mINTSetIFS2(4);
mINTClearIFSx
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
The macro is for all IFS registors. If one would like to clear bits in the
IFS1 register, they need to replace the x with 1
Source File:
None
Code Example:
mINTClearIFS0(1);
mINTClearIFS1(2);
mINTClearIFS2(4);
mINTGetIFSx
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
The macro is for all IFS registors. If one would like to clear bits in the
IFS1 register, they need to replace the x with 1
Source File:
None
Code Example:
if(!mINTGetIFS0(1))
return;
if(mINTGetIFS1(2) == 2)
return;
if(mINTGetIFS2(3) != 3)
return;
-page 77
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
The macro is for all IEC registors. If one would like to set bits in the
IEC1 register, they need to replace the x with 1
Source File:
None
Code Example:
mINTSetIEC0(1);
mINTSetIEC1(2);
mINTSetIEC2(4);
mINTClearIECx
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
The macro is for all IEC registors. If one would like to clear bits in the
IEC1 register, they need to replace the x with 1
Source File:
None
Code Example:
mINTClearIEC0(1);
mINTClearIEC1(2);
mINTClearIEC2(4);
mINTSetIntProximityTimerReload
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
None
Source File:
None.c
Code Example:
mINTSetIntProximityTimerReload(0x0080000);
mINTGetIntProximityTimer
Description:
-page 78
mINTGetIntProximityTimer
Include:
plib.h
Prototype:
Arguments:
None
Return Value
Remarks:
If the proximity timer has not been tiggered, the value that will be read
back is the reload time
Source File:
None
Code Example:
mINTSetFreeze
Description:
Include:
plib.h
Prototype:
void mINTSetFreeze(void)
Arguments:
None
Return Value
None
Remarks:
Source File:
None
Code Example:
mINTSetFreeze();
mINTClearFreeze
Description:
Include:
plib.h
Prototype:
void mINTClearFreeze(void)
Arguments:
None
Return Value
None
Remarks:
Source File:
None
Code Example:
mINTClearFreeze();
mINTSetTemporalProximityControl
Description:
Include:
plib.h
Prototype:
-page 79
interrupts
interrupts
interrupts
interrupts
interrupts
interrupts
interrupts
Return Value
None
Remarks:
None.
Source File:
None
Code Example:
mINTSetTemporalProximityControl(2);
or
or
or
or
or
or
lower
lower
lower
lower
lower
lower
mINTDisableTemporalProximityControl
Description:
Include:
plib.h
Prototype:
void mINTDisableTemporalProximityControl(void)
Arguments:
None
Return Value
None
Remarks:
None.
Source File:
None
Code Example:
mINTSetTemporalProximityControl(2);
...
mINTDisableTemporalProximityControl();
mINTSingleVectorRegisterSelect
-page 80
Description:
This selects the general purpose register set that will be used by the
singled vector handler.
Include:
plib.h
Prototype:
Arguments:
Return Value
None
Remarks:
None.
Source File:
None
Code Example:
mINTSingleVectorRegistorSelect(0);
mINTGetInterruptVectorNumber
Description:
This macro will get the highest pending priority interrupt vector
Include:
plib.h
Prototype:
Arguments:
None
Return Value
Remarks:
None.
Source File:
None
Code Example:
mINTGetInterruptVectorPriority
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value
Remarks:
If all of the pending interrupts have been processed, this macro will
return 0.
Source File:
None
Code Example:
mINTDisableSystemMultiVectorInt
Description:
Include:
plib.h
Prototype:
void mINTDisableSystemMultiVectoredInt(void)
Arguments:
None
Return Value
None.
Remarks:
Source File:
None
Code Example:
mINTDisableSystemMultiVectoredInt();
mINTDisableSystemSingleVectorInt
Description:
Include:
plib.h
Prototype:
void mINTDisableSystemSingleVectoredInt(void)
Arguments:
None
-page 81
None.
Remarks:
Source File:
None
Code Example:
mINTDisableSystemSingleVectoredInt();
7.4
7.4.1
m(xx)ClearIntFlag
Description:
Include:
plib.h
Prototype:
void m(xx)ClearIntFlag(void)
Arguments:
None
Return Value
None
Remarks:
Replace (xx) with the coresponding peripheral from the macro flag
table.
Source File:
None
Code Example:
m(xx)GetIntFlag
Description:
Include:
plib.h
Prototype:
void m(xx)GetIntFlag(void)
Arguments:
None
Return Value
None
Remarks:
Replace (xx) with the coresponding peripheral from the macro flag
table.
Source File:
None
Code Example:
m(xx)IntEnable
-page 82
Description:
This sets or clears the interrupt enable for the specific peripheral.
Include:
plib.h
Prototype:
Arguments:
enable
0 - disable the peripheral interrupt
1 - enable the peripheral interrupt
Return Value
None
m(xx)IntEnable
Remarks:
Replace (xx) with the coresponding peripheral from the macro flag
table.
Source File:
None
Code Example:
TABLE 8-2:
Macro Abreviation(xx)
Peripheral
CT
CS0
CS1
INT0
External Interrupt 0
T1
Timer 1 Interrupt
IC1
OC1
INT1
External Interrupt 1
T2
Timer 2 Interrupt
IC2
OC2
INT2
External Interrupt 2
T3
Timer 3 Interrupt
IC3
OC3
INT3
External Interrupt 3
T4
Timer 4 Interrupt
IC4
OC4
INT4
External Interrupt 4
T5
Timer 5 Interrupt
IC5
OC5
CN
SPI1E
SPI 1 Fault
SPI1TX
SPI1RX
U1E
UART 1 Error
U1RX
UART 1 Receiver
U1TX
UART 1 Transmitter
I2C1B
I2C1S
I2C1M
AD1
PMP
CMP1
Comparator 1 Interrupt
-page 83
Macro Abreviation(xx)
Peripheral
CMP2
Comparator 2 Interrupt
SPI2E
SPI 2 Fault
SPI2TX
SPI2RX
U2E
UART 2 Error
U2RX
UART 2 Receiver
U2TX
UART 2 Transmitter
I2C2B
I2C2S
I2C2M
FSCM
FCE
RTCC
DMA0
DMA1
DMA2
DMA3
DMA4
DMA5
DMA6
DMA7
USB
USB Interrupt
7.4.2
m(yy)SetIntPriority
-page 84
Description:
Include:
plib.h
Prototype:
Arguments:
priority
0 - disable interrupt
1 - priority level 1
2 - priority level 2
3 - priority level 3
4 - priority level 4
5 - priority level 5
6 - priority level 6
7 - priority level 7
Return Value
None
Remarks:
Replace (yy) with the coresponding peripheral from the macro interrupt
vector table.
Source File:
None
Code Example:
m(yy)GetIntPriority
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value
0
1
2
3
4
5
6
7
Remarks:
Replace (yy) with the coresponding peripheral from the macro interrupt
vector table.
Source File:
None
Code Example:
disable interrupt
priority level 1
priority level 2
priority level 3
priority level 4
priority level 5
priority level 6
priority level 7
m(yy)SetIntSubPriority
Description:
Include:
plib.h
Prototype:
Arguments:
subPriority
0 - sub-priority
1 - sub-priority
2 - sub-priority
3 - sub-priority
level
level
level
level
0
1
2
3
Return Value
None
Remarks:
Replace (yy) with the coresponding peripheral from the macro interrupt
vector table.
Source File:
None
Code Example:
m(yy)GetIntSubPriority
Description:
Include:
plib.h
-page 85
Arguments:
None
Return Value
0
1
2
3
Remarks:
Replace (yy) with the coresponding peripheral from the macro interrupt
vector table.
Source File:
None
Code Example:
sub-priority
sub-priority
sub-priority
sub-priority
level
level
level
level
0
1
2
3
TABLE 8-3:
Macro Abreviation(yy)
-page 86
Peripheral
CT
CS0
CS1
INT0
External Vector 0
T1
Timer 1 Vector
IC1
OC1
INT1
External Vector 1
T2
Timer 2 Vector
IC2
OC2
INT2
External Vector 2
T3
Timer 3 Vector
IC3
OC3
INT3
External Vector 3
T4
Timer 4 Vector
IC4
OC4
INT4
External Vector 4
T5
Timer 5 Vector
IC5
OC5
CN
SPI1
SPI 1 Vector
U1
UART 1 Vector
I2C1
I2C 1 Vector
AD1
TABLE 8-3:
Macro Abreviation(yy)
Peripheral
PMP
CMP1
Comparator 1 Vector
CMP2
Comparator 2 Vector
SPI2
SPI 2 Vector
U2
UART 2 Vector
I2C2
I2C 2 Vector
FSCM
FCE
RTCC
DMA0
DMA1
DMA2
DMA3
DMA4
DMA5
DMA6
DMA7
USB
USB Vector
7.4.3
m(zz)ClearAllIntFlag
Description:
This clears all of the interrupt flags assocated with the peripheral
interrupt.
Include:
plib.h
Prototype:
void m(zz)ClearAllIntFlag(void)
Arguments:
None
Return Value
None
Remarks:
Replace (zz) with the coresponding peripheral from the macro flag
table.
Source File:
None
Code Example:
m(zz)IntDisable
Description:
Include:
plib.h
Prototype:
void m(zz)IntDisable(void)
Arguments:
None
Return Value
None
Remarks:
Replace (zz) with the coresponding peripheral from the macro flag
table.
-page 87
None
Code Example:
TABLE 8-4:
Marco Aberivation(zz)
7.5
Multi-Event Peripheral
SPI1
SPI 1
U1
UART 1
I2C1
I2C 1
SPI2
SPI 2
U2
UART 2
I2C2
I2C 2
Software Interrupt
mConfigIntCoreSW0
mConfigIntCoreSW1
Description:
Configures the prioirty, sub priority and enables the core software
interrupt..
Include:
plib.h
Prototype:
void mConfigIntCoreSW0(config)
void mConfigIntCoreSW1(config)
Arguments:
config
-page 88
Return Value
None
Remarks:
None
Source File:
None
mConfigIntCoreSW0
mConfigIntCoreSW1
Code Example:
mEnableIntCoreSW0
mEnableIntCoreSW1
Description:
Include:
plib.h
Prototype:
void mEnableIntCoreSW0(void)
void mEnableIntCoreSW1(void)
Arguments:
None
Return Value
None
Remarks:
none
Source File:
None
Code Example:
mDisableIntCoreSW0
mDisableIntCoreSW1
Description:
Include:
plib.h
Prototype:
void mDisableIntCoreSW0(void)
void mDisableIntCoreSW1(void)
Arguments:
None
Return Value
None
Remarks:
none
Source File:
None
Code Example:
mSetPriorityIntCoreSw0
mSetPriorityIntCoreSw1
Description:
Include:
plib.h
Prototype:
void mSetPriorityIntCoreSW0(priority)
void mSetPriorityIntCoreSW1(priority)
Arguments:
-page 89
None
Remarks:
none
Source File:
None
Code Example:
SetCoreSw0
SetCoreSw1
Description:
Include:
plib.h
Prototype:
void SetCoreSW0(void)
void SetCoreSW1(void)
Arguments:
None
Return Value
None
Remarks:
Source File:
None
Code Example:
ClearCoreSw0
ClearCoreSw1
-page 90
Description:
Include:
plib.h
Prototype:
void ClearCoreSW0(void)
void ClearCoreSW1(void)
Arguments:
None
Return Value
None
Remarks:
The user must clear the software interrupt using this function and also
the the interrupt flag to clear the interrupt request.
Source File:
None
Code Example:
8.0
OSCILLATOR FUNCTIONS
The PIC32MX has multiple clock sources, with varying degrees of adjustability. The
oscillator library functions are available to allow high-level control of the clock source
and scaling of the frequency at runtime. The following functions and macros are available:
8.1
Individual Functions
OSCConfig()
Description:
This sets the desired oscillator source, PLL postscaler, PLL multiplier
and FRC divisor values.
Include:
plib.h
Prototype:
Arguments:
config1
This contains the bit field for the desired clock selection:
Osc Source Mode Select
OSC_FRC_DIV
OSC_FRC_DIV16
OSC_LPRC
OSC_SOSC
OSC_POSC_PLL
OSC_POSC
OSC_FRC_PLL
OSC_FRC
(These bit fields are mutually exclusive)
config2
This contains the bit field for the desired PLL multipler
selection.
-page 91
config3
This contains the bit field for the desired FRC divisor
selection.
config4
None
Remarks:
Code Example:
OscConfig(OSC_POSC_PLL, OSC_PLL_MULT_15,
OSC_PLL_POST_1, 0);
8.2
Individual Macros
mOSCClockFailStatus()
-page 92
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
mOSCClockFailStatus() (Continued)
Code Example:
mOSCDisableSOSC()
Description:
Include:
plib.h
Prototype:
void mOSCDisableSOSC(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mOSCDisableSOSC();
mOSCEnableSOSC()
Description:
Include:
plib.h
Prototype:
void mOSCEnableSOSC(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mOSCEnableSOSC();
-page 93
Include:
plib.h
Prototype:
mOSCGetPBDIV();
Arguments:
None
Return Value:
Remarks:
None
Code Example:
mOSCSetPBDIV()
Description:
Include:
plib.h
Prototype:
Arguments:
config
This contains the bit field for the desired clock selection:
Osc Source Mode Select
OSC_PB_DIV_1
OSC_PB_DIV_2
OSC_PB_DIV_4
OSC_PB_DIV_8
(These bit fields are mutually exclusive)
-page 94
Return Value:
None
Remarks:
Code Example:
mOscSetPBDIV(OSC_PB_DIV_8);
8.3
Example of Use
main()
{
// this example sets the cpu clock to FRC and then to POSC PLL
-page 95
-page 96
9.0
The PIC32MX has two power save modes: Sleep and Idle. The power save library
macros are available to allow high-level control of these mods . The following macros
are available:
mPowerSaveIdle() - Configures the device for Idle mode and enters Idle
mPowerSaveSleep() - Configures the device for Sleep mode and enters Sleep
9.1
Individual Functions
There are no functions to support this module, refer to the macro section
9.2
Individual Macros
mPowerSaveIdle()
Description:
Include:
plib.h
Prototype:
mPowerSaveIdle();
Arguments:
None
Return Value:
None
Source File:
plib.h
Remarks:
Code Example:
mPowerSaveIdle();
mPowerSaveSleep()
Description:
Include:
plib.h
Prototype:
mPowerSaveSleep();
Arguments:
None
Return Value:
None
Source File:
plib.h
Remarks:
Code Example:
mPowerSaveSleep();
main()
{
// this example puts the CPU in Sleep
-page 97
-page 98
10.0
The PIC32MX I/O PORT library consists of simple, code effecient macros and functions supporting common control features for this peripheral. Several functions and macros have a similar
name, but differ by the level of control they provide, Advanced or Basic.
Depending on the application, the advanced functions may provide greater flexibility compared
to the similarly named basic macros, however, at the cost of slightly less efficient code due to
overhead involved when calling any function. The basic macros can generate more efficient
compile-time code. For specific details regarding their operations, refer to the function and
macro descriptions in the following I/O Port sections.
macros or functions and are maintained to provide compatibility for 16-Bit to 32-Bit PIC32MX code migration.
-page 99
Macros
Functions
mPORTASetPinsDigitalIn( ) ...
mPORTGSetPinsDigitalIn( )
PORTSetPinsDigitalIn( )
PORTSetPinsDigitalOut( )
mPORTASetPinsDigitalOut( ) ...
mPORTGSetPinsDigitalOut( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose I/O pins for use as digital inputs and outputs.
Advanced
These functions configure port pins as digital input or digital output and automatically disable analog features that may be multiplexed with the specified pin(s).
Feature: Complete digital I/O pin configuration. These functions meet all the necessary
configuration requirements to properly configure port IO pins that are digital only and those
port IO pins that share analog and digital functionality.
When to use: These functions provide a simple and preferred method to configure digital
I/O pins when the user is not familiar with the details of an I/O port. The user only needs
to specify a PORT and PIN(s).
For example: PORTSetPinsDigitalIn(IOPORT_B, BIT_0)
PORTSetPinsDigitalIn()
PORTSetPinsDigitalOut()
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital I/O pin configuration only.
When to use: These macros provide basic digital I/O pin configuration when the control
of other I/O port aspects or code efficiency is a desire. It is recommended that the user be
familiar with the detailed I/O PORT operation. The user is responsible for disabling any
analog input that may be multiplexed with the specified pin. The user only needs to specify
the PIN(s).
For example: mPORTBSetPinsDigitalIn(BIT_0)
mPORTASetPinsDigitalIn()
...
mPORTGSetPinsDigitalIn()
mPORTASetPinsDigitalOut()
...
mPORTGSetPinsDigitalOut()
-page 100
PORTSetPinsDigitalIn
Description:
Include:
plib.h
Prototype:
Arguments:
port
inputs This argument contains one or more bit masks bitwise ORd
together. Select one or more masks from the mask set
defined below. Note: An absent mask symbol assumes
corresponding bit(s) are disabled, or default value, and
will be set = 0.
IO Pin Bit Masks
BIT_0
BIT_1
BIT_2
...
BIT_15
Return Value:
None
Remarks:
For those IO pins that share digital and analog functionality, the
corresponding ADPCFG bits are set appropriately.
See code example.
Source File:
port_set_pins_digital_in_lib.c
Code Example:
#define PORT
#define PINS
IOPORT_C
BIT_1 | BIT_0
PORTSetPinsDigitalIn(PORT, PINS);
-page 101
Include:
plib.h
Prototype:
Arguments:
port
inputs
Return Value:
None
Remarks:
For those IO pins that share digital and analog functionality, the
corresponding ADPCFG bits are set appropriately.
See code example.
Source File:
port_set_pins_digital_out_lib.c
Code Example:
#define PORT
#define PINS
IOPORT_B
BIT_7
PORTSetPinsDigitalOut(PORT, PINS);
-page 102
mPORTASetPinsDigitalIn
mPORTBSetPinsDigitalIn
mPORTCSetPinsDigitalIn
mPORTDSetPinsDigitalIn
mPORTESetPinsDigitalIn
mPORTFSetPinsDigitalIn
mPORTGSetPinsDigitalIn
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTASetPinsDigitalIn(unsigned
mPORTBSetPinsDigitalIn(unsigned
mPORTCSetPinsDigitalIn(unsigned
mPORTDSetPinsDigitalIn(unsigned
mPORTESetPinsDigitalIn(unsigned
mPORTFSetPinsDigitalIn(unsigned
mPORTGSetPinsDigitalIn(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
Return Value:
None
Remarks:
Source File:
None
Code Example:
/*PORTC<1:0> = inputs */
mPORTCSetPinsDigitalIn(BIT_1 | BIT_0);
/* PORTA<8> inputs, all others not affected */
mPORTASetPinsDigitalIn(0x0100);
-page 103
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTASetPinsDigitalOut(unsigned
mPORTBSetPinsDigitalOut(unsigned
mPORTCSetPinsDigitalOut(unsigned
mPORTDSetPinsDigitalOut(unsigned
mPORTESetPinsDigitalOut(unsigned
mPORTFSetPinsDigitalOut(unsigned
mPORTGSetPinsDigitalOut(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 104
10.2
Functions
mPORTBSetPinsAnalogIn( )
PORTSetPinsAnalogIn( )
mPORTBSetPinsAnalogOut( )
PORTSetPinsAnalogOut( )
Description
Before applying any analog input voltage or enabling an analog output peripheral on those
I/O port pins that are analog capable, typically PORTB only, the data direction of a desired
pin must be properly configured as analog input or analog output. Some port I/O pins
share digital and analog features and require the digital feature to be disabled when configuring the I/O port pin for analog mode. Note, on Power-on Reset, analog is the default
mode for those I/O port pins that share digital and analog features.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose I/O pins for use as analog inputs and outputs.
Advanced
These functions configure port pins as analog input or analog output and automatically
disable digital features that may be multiplexed with the specified pin(s).
Feature: Complete analog I/O pin configuration. These functions meet all the necessary
configuration requirements to properly configure port I/O pins that share analog and digital functionality.
When to use: These functions provide a simple and preferred method to configure analog I/O pins when the user is not familiar with the details of an I/O port. The user only
needs to specify a PORT and PIN(s).
For example: PORTSetPinsAnalogIn(IOPORT_B, BIT_0)
PORTSetPinsAnalogIn
PORTSetPinsAnalogOut
Basic
These macros configure port pins as analog input or analog output.
Feature: Simple analog I/O pin configuration only.
When to use: These macros provide basic analog I/O pin configuration when the control
of other I/O port aspects or code efficiency is a desire. It is recommended that the user be
familiar with the detailed I/O PORT operation. The user is responsible for disabling any
analog input that may be multiplexed with the specified pin. The user only needs to specify
the PIN(s).
For example: mPORTBSetPinsDigitalIn(BIT_0)
mPORTBSetPinsAnalogIn
mPORTBSetPinsAnalogOut
-page 105
Include:
plib.h
Prototype:
Arguments:
port
inputs
Return Value:
None
Remarks:
For those IO pins that share digital and analog functionality, the
corresponding ADPCFG bits are set appropriately.
See code example.
Source File:
port_set_pins_analog_in_lib.c
Code Example:
#define PORT
#define PINS
IOPORT_B
BIT_1 | BIT 0
PORTSetPinsAnalogIn(PORT, PINS);
-page 106
PORTSetPinsAnalogOut
Description:
Include:
plib.h
Prototype:
Arguments:
port
inputs
Return Value:
None
Remarks:
For those IO pins that share digital and analog functionality, the
corresponding ADPCFG bits are set appropriately.
See code example.
Source File:
port_set_pins_analog_out_lib.c
Code Example:
#define PORT
#define PINS
IOPORT_B
BIT_10
PORTSetPinsAnalogOut(PORT, PINS);
-page 107
Include:
plib.h
Prototype:
Arguments:
_bits
-page 108
Return Value:
None
Remarks:
Source File:
None
Code Example:
mPORTBSetPinsAnalogOut
Description:
Include:
plib.h
Prototype:
Arguments:
_bits
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 109
Description
At Power-On Reset, all I/O pins default to inputs. Before reading and writing to any I/O
port, the data direction of an I/O pin must be properly configured as input or ouput.
Useage
These functions are typically used early in the program execution to establish the desired
direction of the general purpose IO pins. Macros mPORTxDirection(), mPORTxGetDirection() and mCloseAll() operate directly on the TRIS register and therefore
modifiy the entire register with the contents of the argument. Macros mPORTxCloseBits()
and mPORTAReadDirectionBits() will only affect those bits specified in the argument.
Note: To specify input and output direction on specific pins without affecting neighboring
pin configuration on the target port, use macros mPORTxSetPinsDigitalIn() or mPORTxSetPinsDigitalOut().
Basic
These macros configure port pin directions.
Feature: Simple I/O pin direction configuration only.
When to use: Use these macros to configure a ports direction (TRIS) register. It is recommended that the user is familiar with the detailed IO PORT operation. The user is
responsible for disabling any analog input that may be multiplexed with the specified pin.
The user only needs to specify the PIN(s).
For example: mPORTFDirection(BIT_7)
mPORTADirection()
...
mPORTGDirection()
mPORTAGetDirection()
...
mPORTGGetDirection()
mPORTAReadDirectionBits()
...
mPORTGReadDirectionBits()
mPORTACloseBits()
...
mPORTGCloseBits()
mPORTACloseAll()
...
-page 110
mPORTGCloseAll()
mPORTADirection
mPORTBDirection
mPORTCDirection
mPORTDDirection
mPORTEDirection
mPORTFDirection
mPORTGDirection
Description:
This macro configures the complete TRISx register. Both inputs and
outputs are specified in the argument.
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTADirection(unsigned
mPORTBDirection(unsigned
mPORTCDirection(unsigned
mPORTDDirection(unsigned
mPORTEDirection(unsigned
mPORTFDirection(unsigned
mPORTGDirection(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
None
Remarks:
Argument is copied to the TRISx register, therefore all bits are modified.
If a bit is = 1, the corresponding IO pin becomes an input; if a bit = 0,
the corresponding IO pin becomes an output. See code example.
Source File:
None
Code Example:
-page 111
This macro sets the specified IO Port pin as input and clears its
corresponding LATx register bit.
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTACloseBits(unsigned
mPORTBCloseBits(unsigned
mPORTCCloseBits(unsigned
mPORTDCloseBits(unsigned
mPORTECloseBits(unsigned
mPORTFCloseBits(unsigned
mPORTGCloseBits(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
-page 112
Return Value:
None
Remarks:
Source File:
None
Code Example:
mPORTACloseAll
mPORTBCloseAll
mPORTCCloseAll
mPORTDCloseAll
mPORTECloseAll
mPORTFCloseAll
mPORTGCloseAll
Description:
This macro sets all IO Port pins as input and clears their corresponding
LATx register bits.
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
/* close PORTA */
mPORTACloseAll();
mPORTACloseAll(void);
mPORTBCloseAll(void);
mPORTCCloseAll(void);
mPORTDCloseAll(void);
mPORTECloseAll(void);
mPORTFCloseAll(void);
mPORTGCloseAll(void);
-page 113
-page 114
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
None
Remarks:
Source File:
None
Code Example:
mPORTAGetDirection(void);
mPORTBGetDirection(void);
mPORTCGetDirection(void);
mPORTDGetDirection(void);
mPORTEGetDirection(void);
mPORTFGetDirection(void);
mPORTGGetDirection(void);
mPORTAReadDirectionBits
mPORTBReadDirectionBits
mPORTCReadDirectionBits
mPORTDReadDirectionBits
mPORTEReadDirectionBits
mPORTFReadDirectionBits
mPORTGReadDirectionBits
Description:
Include:
plib.h
Prototype:
Arguments:
_bits
Return Value:
None
Remarks:
The bit mask is bitwise ANDd with the contents of the TRISx register.
See code example
Source File:
None
Code Example:
-page 115
Macros
mPORTAOpenDrainOpen( ) ...
mPORTGOpenDrainOpen( )
mPORTAOpenDrainClose( ) ...
mPORTGOpenDrainClose( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mPORTBSetPinsDigitalIn(BIT_0)
mPORTxOpenDrainOpen
mPORTxOpenDrainClose
-page 116
mPORTAOpenDrainOpen
mPORTBOpenDrainOpen
mPORTCOpenDrainOpen
mPORTDOpenDrainOpen
mPORTEOpenDrainOpen
mPORTFOpenDrainOpen
mPORTGOpenDrainOpen
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits This argument contains one or more bit masks bitwise ORd
together. Select one or more masks from the mask set
defined below. Note: An absent mask symbol assumes
corresponding bit(s) are disabled, or default value, and
will be set = 0.
mPORTAOpenDrainOpen(unsigned
mPORTBOpenDrainOpen(unsigned
mPORTCOpenDrainOpen(unsigned
mPORTDOpenDrainOpen(unsigned
mPORTEOpenDrainOpen(unsigned
mPORTFOpenDrainOpen(unsigned
mPORTGOpenDrainOpen(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
None
Remarks:
Source File:
None
Code Example:
-page 117
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTAOpenDrainClose(unsigned
mPORTBOpenDrainClose(unsigned
mPORTCOpenDrainClose(unsigned
mPORTDOpenDrainClose(unsigned
mPORTEOpenDrainClose(unsigned
mPORTFOpenDrainClose(unsigned
mPORTGOpenDrainClose(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
-page 118
Return Value:
None
Remarks:
To disable a specific IO pin open-drain output, include its bit mask in the
argument. If a mask bit is = 1, the corresponding TRISx bit is set = 1
(input) and corresponding IO pin open drain feature is disabled; if a
mask bit = 0, the corresponding IO pin is not affected. See code
example.
Source File:
None
Code Example:
10.5
Macros
mCNOpen( )
mCNClose( )
mCNEnable( )
*ConfigIntCN( )
*EnableCN0( ) ...
*EnableCN21( )
*DisableCN0( ) ...
*DisableCN21( )
*ConfigCNPullups( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mPORTBSetPinsDigitalIn(BIT_0)
*ConfigIntCN
*EnableCNx
*DisableCNx
ConfigCNPullups
mCNOpen
mCNClose
mCNEnable
* = Legacy
-page 119
This legacy macro sets the priority level for the Change Notice pins.
Include:
plib.h
Prototype:
Arguments:
_bits
Return Value:
None
Remarks:
Change notice interrupt flag is cleared, priority level is set and interrupt
is enabled.
Note: Not all IO pins provide a change notice interrupt feature. Refer
to the specific PIC32MX datasheet regarding the IO pins that support
the change notice feature.
See code example.
-page 120
Source File:
None
Code Example:
*EnableCN0
*EnableCN1
*EnableCN2
...
*EnableCN21
Description:
Include:
plib.h
Prototype:
void
void
void
...
void
void
EnableCN0(void);
EnableCN1(void);
EnableCN2(void);
EnableCN21(void);
EnableCN_ALL(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 121
-page 122
Description:
Include:
plib.h
Prototype:
void
void
void
...
void
void
DisableCN0(void);
DisableCN1(void);
DisableCN2(void);
DisableCN21(void);
DisbleCN_ALL(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
*ConfigCNPullups
Description:
Include:
plib.h
Prototype:
Arguments:
_bits
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 123
This macro configures the change notice pins and the associated
pullups.
Include:
plib.h
Prototype:
Arguments:
_config This argument contains one or more bit masks bitwise ORd
together. Select only one mask from each of the three mask
sets defined below. Note: An absent mask symbol
assumes corresponding bit(s) are disabled, or default
value, and will be set = 0.
CN module On/Off
CN_ON
CN_OFF
CN debug freeze mode On/Off
CN_FRZ_ON
CN_FRZ_OFF
CN idle mode On/Off
CN_IDLE_CON
CN_IDLE_STOP
_pins
-page 124
Return Value:
None
Notes:
mCNOpen (Continued)
Remarks:
Source File:
None
Code Example:
#define
#define
#define
#define
CONFIG
PINS
PULLUPS
INTERRUPT
(CN_ON | CN_IDLE_CON)
(CN15_ENABLE)
(CN_PULLUP_DISABLE_ALL)
(CHANGE_INT_ON | CHANGE_INT_PRI_2)
-page 125
Include:
plib.h
Prototype:
void mCNClose(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
mCNEnable
Description:
Include:
plib.h
Prototype:
Arguments:
_bits
-page 126
Return Value:
None
Remarks:
Source File:
None
Code Example:
10.6
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mPORTBSetPinsDigitalIn(BIT_0)
*ConfigINTx
*CloseINTx
*EnableINTx
*DisableINTx
SetPriorityINTx
SetSubPriorityINTx
-page 127
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
_bits
ConfigInt0(unsigned
ConfigInt1(unsigned
ConfigInt2(unsigned
ConfigInt3(unsigned
ConfigInt4(unsigned
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
-page 128
Return Value:
None
Remarks:
Source File:
None
Code Example:
*EnableINT0
*EnableINT1
*EnableINT2
*EnableINT3
*EnableINT4
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
EnableInt0(void);
EnableInt1(void);
EnableInt2(void);
EnableInt3(void);
EnableInt4(void);
*DisableINT0
*DisableINT1
*DisableINT2
*DisableINT3
*DisableINT4
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
DisableInt0(void);
DisableInt1(void);
DisableInt2(void);
DisableInt3(void);
DisableInt4(void);
-page 129
-page 130
Description:
These legacy macros disable the specified external interrupt and clears
interrupt flag.
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
CloseInt0(void);
CloseInt1(void);
CloseInt2(void);
CloseInt3(void);
CloseInt4(void);
*SetPriorityINT0
*SetPriorityINT1
*SetPriorityINT2
*SetPriorityINT3
*SetPriorityINT4
Description:
These legacy macros set the priority level for the specified external
interrupt pin.
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
_bits
SetPriorityInt0(unsigned
SetPriorityInt1(unsigned
SetPriorityInt2(unsigned
SetPriorityInt3(unsigned
SetPriorityInt4(unsigned
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
This argument contains one bit mask. Select only one mask
from the mask set defined below. Note: An absent mask
symbol assumes corresponding bit(s) are disabled, or
default value, and will be set = 0.
External Interrupt Priority Bit Masks
EXT_INT_PRI_0
EXT_INT_PRI_1
EXT_INT_PRI_2
...
EXT_INT_PRI_7
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 131
These macros set the sub-priority level for the specified external
interrupt pin.
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
_bits
SetSubPriorityINT0(unsigned
SetSubPriorityINT1(unsigned
SetSubPriorityINT2(unsigned
SetSubPriorityINT3(unsigned
SetSubPriorityINT4(unsigned
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
This argument contains one bit mask. Select only one mask
from the mask set defined below. Note: An absent mask
symbol assumes corresponding bit(s) are disabled, or
default value, and will be set = 0.
External Interrupt Sub Priority Bit Masks
EXT_INT_SUB_PRI_0
EXT_INT_SUB_PRI_1
EXT_INT_SUB_PRI_2
EXT_INT_SUB_PRI_3
-page 132
Return Value:
None
Remarks:
Source File:
None
Code Example:
10.7
READ OPERATIONS
Macros
Functions
mPORTARead( ) ...
mPORTGRead( )
PORTRead( )
PORTReadBits( )
mPORTAReadBits( ) ...
mPORTGReadBits( )
mPORTAReadLatch( ) ...
mPORTGReadLatch( )
mPORTAReadLatchBits( ) ...
mPORTGReadLatchBits( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Advanced
These functions configure port pins as digital input or digital output and automatically disable analog inputs that may be multiplexed with the specified pin(s).
Feature: Complete digital IO pin configuration. These functions meet all the necessary
configuration requirements to properly configure port IO pins that are digital only and those
port IO pins that share analog and digital functionality.
When to use: These functions provide a simple and preferred method to configure digital
I/O pins when the user is not familiar with the details of an I/O port. The user only needs
to specify a PORT and PIN(s).
For example: PORTRead(IOPORT_B)
PORTRead
PORTReadBits
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mPORTBReadLatchBits(BIT_0)
mPORTxRead
mPORTxReadBits
mPORTxReadLatch
mPORTxReadLatchBits
-page 133
Include:
plib.h
Prototype:
Arguments:
port
Return Value:
Remarks:
Source File:
port_read_lib.c
Code Example:
/* read PORT C */
value = PORTRead(IOPORT_C);
PORTReadBits
Description:
This function reads and returns only the specified bits from a specified
PORT.
Include:
plib.h
Prototype:
Arguments:
port
_bits
-page 134
PORTReadBits (Continued)
IO Pin Bit Masks
BIT_0
BIT_1
BIT_2
...
BIT_15
Return Value:
unsigned int = value read from specified PORT register bitwise ANDd
with _bits parameter.
Remarks:
Source File:
port_read_bits_lib.c
Code Example:
/* read PORT C */
value = PORTReadBits(IOPORT_C, BIT_7 | BIT_6);
-page 135
-page 136
Description:
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
None
Return Value:
Remarks:
Source File:
None
Code Example:
/* read PORT C */
value = mPORTCRead();
int
int
int
int
int
int
int
mPORTARead(void);
mPORTBRead(void);
mPORTCRead(void);
mPORTDRead(void);
mPORTERead(void);
mPORTFRead(void);
mPORTGRead(void);
mPORTAReadBits
mPORTBReadBits
mPORTCReadBits
mPORTDReadBits
mPORTEReadBits
mPORTFReadBits
mPORTGReadBits
Description:
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
_bits
int
int
int
int
int
int
int
mPORTAReadBits(unsigned
mPORTBReadBits(unsigned
mPORTCReadBits(unsigned
mPORTDReadBits(unsigned
mPORTEReadBits(unsigned
mPORTFReadBits(unsigned
mPORTGReadBits(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
Return Value:
None
Remarks:
The bit mask is bitwise ANDd with the contents of the PORTx register.
See code example
Source File:
None
Code Example:
mPORTAReadLatch
mPORTBReadLatch
mPORTCReadLatch
mPORTDReadLatch
mPORTEReadLatch
mPORTFReadLatch
mPORTGReadLatch
Description:
-page 137
-page 138
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
None
Return Value:
None
Remarks:
Source File:
None
Code Example:
int
int
int
int
int
int
int
mPORTAReadLatch(void);
mPORTBReadLatch(void);
mPORTCReadLatch(void);
mPORTDReadLatch(void);
mPORTEReadLatch(void);
mPORTFReadLatch(void);
mPORTGReadLatch(void);
mPORTAReadLatchBit
mPORTBReadLatchBit
mPORTCReadLatchBit
mPORTDReadLatchBit
mPORTEReadLatchBit
mPORTFReadLatchBit
mPORTGReadLatchBit
Description:
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
_bits This argument contains one or more bit masks bitwise ORd
together. Select one or more masks from the mask set
defined below. Note: An absent mask symbol assumes
corresponding bit(s) are disabled, or default value, and
will be set = 0.
int
int
int
int
int
int
int
mPORTAReadLatchBit(unsigned
mPORTBReadLatchBit(unsigned
mPORTCReadLatchBit(unsigned
mPORTDReadLatchBit(unsigned
mPORTEReadLatchBit(unsigned
mPORTFReadLatchBit(unsigned
mPORTGReadLatchBit(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
None
Remarks:
The bit mask is bitwise ANDd with the contents of the LATx register.
See code example
Source File:
None
Code Example:
-page 139
WRITE OPERATIONS
Functions
Macros
mPORTAWrite( ) ...
mPORTGWrite( )
PORTWrite( )
mPORTASetBits( ) ...
mPORTGSetBits( )
PORTClearBits( )
mPORTAClearBits( ) ...
mPORTGClearBits( )
PORTSetBits( )
PORTToggleBits( )
mPORTAToggleBits( ) ...
mPORTGToggleBits( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Advanced
These functions configure port pins as digital input or digital output and automatically disable analog inputs that may be multiplexed with the specified pin(s).
Feature: Complete digital IO pin configuration. These functions meet all the necessary
configuration requirements to properly configure port IO pins that are digital only and those
port IO pins that share analog and digital functionality.
When to use: These functions provide a simple and preferred method to configure digital
I/O pins when the user is not familiar with the details of an I/O port. The user only needs
to specify a PORT and PIN(s).
For example: PORTSetPinsDigitalIn(IOPORT_B, BIT_0)
PORTWrite
PORTSetBits
PORTClearBits
PORTToggleBits
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mPORTGToggleBits(BIT_0 | BIT_4)
mPORTxWrite
mPORTxClearBits
mPORTxSetBits
mPORTxToggleBits
-page 140
PORTWrite
Description:
This function writes the specified value to the selected PORT register
Include:
plib.h
Prototype:
Arguments:
port
bits
Return Value:
None
Remarks:
This function writes directly to the selected PORT register. In this way,
all bits in the PORT register are affected.
Source File:
port_write_lib.c
Code Example:
PORTWrite(IOPORT_B, BIT_5);
or
PORTWrite(IOPORT_B, 0xC4FF);
-page 141
Include:
plib.h
Prototype:
Arguments:
port
bits
-page 142
Return Value:
None
Remarks:
Source File:
port_set_bits_lib.c
Code Example:
PORTClearBits
Description:
Include:
plib.h
Prototype:
Arguments:
port
bits
Return Value:
None
Remarks:
Source File:
port_clear_bits_lib.c
Code Example:
PORTClearBits(IOPORT_C, BIT_2);
or
PORTClearBits(IOPORT_E, 0xFFFF);
-page 143
Include:
plib.h
Prototype:
Arguments:
port
bits
-page 144
Return Value:
None
Remarks:
Source File:
port_toggle_bits_lib.c
Code Example:
PORTToggleBits(IOPORT_B, BIT_0);
or
PORTToggleBits(IOPORT_G, 0x08);
mPORTAWrite
mPORTBWrite
mPORTCWrite
mPORTDWrite
mPORTEWrite
mPORTFWrite
mPORTGWrite
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_value
Return Value:
None
Remarks:
Source File:
None
Code Example:
mPORTAWrite(unsigned
mPORTBWrite(unsigned
mPORTCWrite(unsigned
mPORTDWrite(unsigned
mPORTEWrite(unsigned
mPORTFWrite(unsigned
mPORTGWrite(unsigned
int
int
int
int
int
int
int
_value);
_value);
_value);
_value);
_value);
_value);
_value);
-page 145
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTAClearBits(unsigned
mPORTBClearBits(unsigned
mPORTCClearBits(unsigned
mPORTDClearBits(unsigned
mPORTEClearBits(unsigned
mPORTFClearBits(unsigned
mPORTGClearBits(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
-page 146
Return Value:
None
Remarks:
Source File:
None
Code Example:
mPORTASetBits
mPORTBSetBits
mPORTCSetBits
mPORTDSetBits
mPORTESetBits
mPORTFSetBits
mPORTGSetBits
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTASetBits(unsigned
mPORTBSetBits(unsigned
mPORTCSetBits(unsigned
mPORTDSetBits(unsigned
mPORTESetBits(unsigned
mPORTFSetBits(unsigned
mPORTGSetBits(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
Return Value:
None
Remarks:
Source File:
None
Code Example:
-page 147
Include:
plib.h
Prototype:
void
void
void
void
void
void
void
Arguments:
_bits
mPORTAToggleBits(unsigned
mPORTBToggleBits(unsigned
mPORTCToggleBits(unsigned
mPORTDToggleBits(unsigned
mPORTEToggleBits(unsigned
mPORTFToggleBits(unsigned
mPORTGToggleBits(unsigned
int
int
int
int
int
int
int
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
_bits);
-page 148
Return Value:
None
Remarks:
Source File:
None
Code Example:
/* Toggle PORTB<2:1> */
mPORTBToggleBits(BIT_2 | BIT_1);
10.9
MISC OPERATIONS
Macros
Functions
mJTAGPortEnable( )
PORTResetPins( )
Description
Before reading and writing to any I/O port, the data direction of a desired pin must be properly configured as digital input or digital output. Some port I/O pins share digital and analog features and require the analog feature to be disabled when configuring the I/O port
pin for digital mode.
Useage
These functions are typically used early in the program execution to establish the proper
mode and state of the general purpose IO pins.
Advanced
These functions configure port pins as digital input or digital output and automatically disable analog inputs that may be multiplexed with the specified pin(s).
Feature: Complete digital IO pin configuration. These functions meet all the necessary
configuration requirements to properly configure port IO pins that are digital only and those
port IO pins that share analog and digital functionality.
When to use: These functions provide a simple and preferred method to configure digital
I/O pins when the user is not familiar with the details of an I/O port. The user only needs
to specify a PORT and PIN(s).
For example: PORTResetPins(IOPORT_B, BIT_0)
PORTResetPins
Basic
These macros configure port pins as digital input or digital output.
Feature: Simple digital IO pin configuration only.
When to use: These macros provide basic digital IO pin configuration for users who need
to control other aspects of the port IO pin configuration and it is recommended that the
user is familiar with the detailed IO PORT operation. The user is responsible for disabling
any analog input that may be multiplexed with the specified pin. The user only needs to
specify the PIN(s).
For example: mJTAGPortEnable(DEBUG_JTAGPORT_OFF)
mJTAGPortEnable()
mJTAGPortEnable
Description:
Include:
plib.h
Prototype:
Arguments:
_enable
-page 149
PORTResetPins()
Return Value:
None
Remarks:
Source File:
None
Code Example:
PORTResetPins
Description:
Include:
plib.h
Prototype:
Arguments:
port
bits
-page 150
Return Value:
None
Remarks:
Source File:
port_reset_pins.c
Code Example:
CONFIG
PINS
PULLUPS
INTERRUPT
(CN_ON | CN_IDLE_CON)
(CN15_ENABLE)
(CN_PULLUP_DISABLE_ALL)
(CHANGE_INT_ON | CHANGE_INT_PRI_2)
// BIT_2 = 1
// BIT_2 = 0
}
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void)
{
// clear the mismatch condition
mPORTDRead();
// clear the interrupt flag
mCNClearIntFlag();
// toggle the led
mPORTAToggleBits(BIT_3);
asm ("nop");
// BIT_3 = TOGGLE
-page 151
-page 152
11.0
TIMER FUNCTIONS
The PIC32MX TIMER library consists of functions and macros supporting common configuration
and control features.
CPU Core Timer Operations
OpenCoreTimer
UpdateCoreTimer
mConfigIntCoreTimer
mEnableIntCoreTimer
mDisableIntCoreTimer
mSetPriorityIntCoreTimer
ReadCoreTimer
WriteCoreTimer
General Purpose Timer Common Operations
OpenTImerx
CloseTimerx
ConfigIntTimerx
SetPriorityIntTx
DisableIntTx
EnableIntTx
General Purpose Timer and Period Read/Write Operations
ReadTimerx
WriteTimerx
ReadPeriodx
WritePeriodx
Advanced
-page 153
OpenCoreTimer
Description:
Include:
plib.h
Prototype:
Arguments:
period
Return Value:
None
Remarks:
This function clears the CPU Core Count register, then loads the CPU
Core Compare register with period.
Source File:
Code Example:
OpenCoreTimer(0x00004000);
UpdateCoreTimer
Description:
Include:
plib.h
Prototype:
Arguments:
period
Return Value:
None
Remarks:
This function adds period to the current value in the CPU Core
Compare register, effectively creating the next period match.
void _CoreTimerHandler(void)
{
mCTClearIntFlag();
UpdateCoreTimer(CORE_TIMER_PERIOD);
// .. things to do .. add code here
}
-page 154
Advanced
mConfigIntCoreTimer
Description:
Include:
plib.h
Prototype:
void mConfigIntCoreTimer(config);
Arguments:
config
Return Value:
None
Remarks:
This macro clears the Core Timer interrupt flag, sets the priority and
sub-priority interrupt level then enables the Core Timer interrupt.
Source File:
Code Example:
mConfigIntCoreTimer(CT_INT_ON | CT_INT_PRIOR_4);
mEnableIntCoreTimer
Description:
Include:
plib.h
Prototype:
mEnableIntCoreTimer();
Arguments:
None
Return Value:
None
Remarks:
Source File:
Code Example:
mEnableIntCoreTimer();
Advanced
-page 155
Include:
plib.h
Prototype:
void mDisableIntCoreTimer(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
Code Example:
mDisableIntCoreTimer();
mSetPriorityIntCoreTimer
Description:
This macro sets the 32-bit CPU Core Timer interrupt priority.
Include:
plib.h
Prototype:
Arguments:
priority This argument is the priority value for the CPU Core Timer
interrupt level.
Core Timer Priority Interrupt Levels
CT_INT_PRIOR_7
CT_INT_PRIOR_6
CT_INT_PRIOR_5
CT_INT_PRIOR_4
CT_INT_PRIOR_3
CT_INT_PRIOR_2
CT_INT_PRIOR_1
CT_INT_PRIOR_0
Return Value:
None
Remarks:
This function modifies the previously set priority without any need to
specify other parameters.
Source File:
Code Example:
-page 156
mCTSetIntPriority(CT_INT_PRIOR_2);
Advanced
ReadCoreTimer
Description:
This function returns the 32-bit CPU Core Timer register value.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
Source File:
Code Example:
WriteCoreTimer
Description:
This function writes a 32-bit value to the CPU Core Timer register.
Include:
plib.h
Prototype:
Arguments:
period
Return Value:
None
Remarks:
Source File:
Code Example:
WriteCoreTimer(0x12345678);
Advanced
-page 157
OpenTimer1
OpenTimer2
OpenTimer3
OpenTimer4
OpenTimer5
Description:
Include:
plib.h
Prototype:
void OpenTimer1(unsigned
unsigned
void OpenTimer2(unsigned
unsigned
void OpenTimer3(unsigned
unsigned
void OpenTimer4(unsigned
unsigned
void OpenTimer5(unsigned
unsigned
Arguments:
config
int
int
int
int
int
int
int
int
int
int
config,
period);
config,
period);
config,
period);
config,
period);
config,
period);
-page 158
Advanced
OpenTimer1
OpenTimer2
OpenTimer3
OpenTimer4
OpenTimer5 (Continued)
Timer Prescaler(1)
T1_PS_1_1
T1_PS_1_8
T1_PS_1_64
T1_PS_1_256
Timer Prescaler
Tx_PS_1_1
Tx_PS_1_2
Tx_PS_1_4
Tx_PS_1_8
Tx_PS_1_16
Tx_PS_1_32
Tx_PS_1_64
Tx_PS_1_256
(These bit fields are mutually exclusive)
Timer Synchronous clock enable(1)
Tx_SYNC_EXT_ON
(These bit fields are mutually exclusive)
Timer Clock source
Tx_SOURCE_EXT
(These bit fields are mutually exclusive)
period
This argument contains the 16-bit period value for the Timer.
Return Value:
None
Remarks:
This macro clears the TMRx register, writes period to the PRx register
and writes config to the TxCON register
Source File:
Code Example:
OpenTimer23
OpenTimer45
Description:
This function configures Timer2 and Timer3 pair or Timer4 and Timer5
pair as 32-bit timers.
Include:
plib.h
Prototype:
Advanced
config,
period);
config,
period);
-page 159
config
period
Return Value:
None
Remarks:
Source File:
-page 160
Advanced
OpenTimer23
OpenTimer45 (Continued)
Code Example:
CloseTimer1
CloseTimer2
CloseTimer3
CloseTimer4
CloseTimer5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
CloseTimer1(void);
CloseTimer2(void);
CloseTimer3(void);
CloseTimer4(void);
CloseTimer5(void);
Source File:
Code Example:
CloseTimer1();
Close23Timer
Close45Timer
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
Source File:
Code Example:
CloseTimer23();
Advanced
-page 161
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
config
ConfigIntTimer1(unsigned
ConfigIntTimer2(unsigned
ConfigIntTimer3(unsigned
ConfigIntTimer4(unsigned
ConfigIntTimer5(unsigned
int
int
int
int
int
config);
config);
config);
config);
config);
Return Value:
None
Remarks:
Source File:
Code Example:
-page 162
Advanced
ConfigIntTimer23
ConfigIntTimer45
Description:
Include:
plib.h
Prototype:
Arguments:
config
None
Remarks:
Source File:
Code Example:
Advanced
-page 163
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
config
SetPriorityIntT1(unsigned
SetPriorityIntT2(unsigned
SetPriorityIntT3(unsigned
SetPriorityIntT4(unsigned
SetPriorityIntT5(unsigned
int
int
int
int
int
config);
config);
config);
config);
config);
Return Value:
None
Remarks:
Source File:
Code Example:
-page 164
Advanced
SetPriorityIntT23
SetPriorityIntT45
Description:
Include:
plib.h
Prototype:
Arguments:
config
None
Remarks:
Source File:
Code Example:
Advanced
-page 165
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
DisableIntT1(void);
DisableIntT2(void);
DisableIntT3(void);
DisableIntT4(void);
DisableIntT5(void);
Source File:
Code Example:
DisableIntT23
DisableIntT45
Description:
Include:
plib.h
Prototype:
void DisableIntT23(void);
void DisableIntT45(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
Code Example:
-page 166
Advanced
EnableIntT1
EnableIntT2
EnableIntT3
EnableIntT4
EnableIntT5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
EnableIntT1(void);
EnableIntT2(void);
EnableIntT3(void);
EnableIntT4(void);
EnableIntT5(void);
Source File:
Code Example:
EnableIntT23
EnableIntT45
Description:
Include:
plib.h
Prototype:
void EnableIntT23(void);
void EnableIntT45(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
Code Example:
Advanced
-page 167
ReadTimer1
ReadTimer2
ReadTimer3
ReadTimer4
ReadTimer5
Description:
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
None
Return Value:
16-bit timer
Remarks:
This macro returns the contents of the 16-bit timer module timer
register.
int
int
int
int
int
ReadTimer1(void);
ReadTimer2(void);
ReadTimer3(void);
ReadTimer4(void);
ReadTimer5(void);
Source File:
Code Example:
/* Read timer 4 */
currentValue = ReadTimer4();
ReadTimer23
ReadTimer45
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
32-bit timer
Remarks:
Source File:
Code Example:
/* Read timer 45 */
currentValue = ReadTimer45();
-page 168
Advanced
WriteTimer1
WriteTimer2
WriteTimer3
WriteTimer4
WriteTimer5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
Return Value:
None
Remarks:
WriteTimer1(unsigned
WriteTimer2(unsigned
WriteTimer3(unsigned
WriteTimer4(unsigned
WriteTimer5(unsigned
int);
int);
int);
int);
int);
Source File:
Code Example:
/* Write timer 1 */
WriteTimer1(0x0400);
WriteTimer23
WriteTimer45
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
This macro writes the 32-bit value into the TMR register pair.
Source File:
Code Example:
/* Write timer 45 */
WriteTimer45(0x00000000);
Advanced
-page 169
ReadPeriod1
ReadPeriod2
ReadPeriod3
ReadPeriod4
ReadPeriod5
Description:
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
None
Return Value:
16-bit Period
Remarks:
int
int
int
int
int
ReadPeriod1(void);
ReadPeriod2(void);
ReadPeriod3(void);
ReadPeriod4(void);
ReadPeriod5(void);
Source File:
Code Example:
/* Read Period 4 */
currentValue = ReadPeriod4();
ReadPeriod23
ReadPeriod45
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
32-bit Period
Remarks:
Source File:
Code Example:
/* Read Period 45 */
currentValue = ReadPeriod45();
-page 170
Advanced
WritePeriod1
WritePeriod2
WritePeriod3
WritePeriod4
WritePeriod5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
Return Value:
None
Remarks:
WritePeriod1(unsigned
WritePeriod2(unsigned
WritePeriod3(unsigned
WritePeriod4(unsigned
WritePeriod5(unsigned
int);
int);
int);
int);
int);
Source File:
Code Example:
/* Write Period 1 */
WritePeriod1(0x0400);
WritePeriod23
WritePeriod45
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
This macro writes the 32-bit value into the 32-bit Period register.
Source File:
Code Example:
/* Write Period 45 */
WritePeriod45(0x00000000);
Advanced
-page 171
The following code example illustrates the PIC32MX CPU Core Timer and ISR (Interrupt Service
Routine) generating a 10 msec (100 tick / second) periodic interrupt.
Note: The PIC32MX CPU Core Timer Compare register must be updated with a new period
match value after each match occurs. See function UpdateCoreTimer().
A typical application is a kernel time tick for RTOS or simple scheduler.
#include <plib.h>
/* This example assumes the CPU Core is operating at 60MHz */
#define FOSC
60E6
#define CORE_TICK_PERIOD
(FOSC/100)
int main(void)
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 1. configure the core timer
OpenCoreTimer(CORE_TICK_PERIOD);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 2. set core timer interrupt level = 2
mConfigIntCoreTimer(CT_INT_ON | CT_INT_PRIOR_2);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 3. enable multi-vector interrupts
INTEnableSystemMultiVectoredInt();
... do something useful here ...
while(1);
}
/* Core Timer ISR */
/* Specify Interrupt Priority Level = 2, Vector 0 */
void __ISR(_CORE_TIMER_VECTOR, ipl2) _CoreTimerHandler(void)
{
// clear the interrupt flag
mCTClearIntFlag();
// update the period
UpdateCoreTimer(CORE_TICK_PERIOD);
// .. things to do ..
}
-page 172
Advanced
11.6
The following code example illustrates a 16-bit Timer and ISR (Interrupt Service Routine) generating a 250 msec (4 tick / second) periodic interrupt.
Note: The PIC32MX peripheral timers do not require the period match value be reloaded after
each match occurs.
#include <p32xxxx.h>
#include <plib.h>
/* This example assumes the CPU Core is operating at 60MHz */
#define
#define
#define
#define
FOSC
PB_DIV
PRESCALE
T1_TICK
60E6
8
256
(FOSC/PB_DIV/PRESCALE/4)
int main(void)
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 1. configure the Timer1
OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_256, T1_TICK);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 2. set the timer interrupt to prioirty level 2
ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 3. enable multi-vector interrupts
INTEnableSystemMultiVectoredInt();
... do something useful here ...
while(1);
}
/* Timer 1 ISR */
/* Specify Interrupt Priority Level = 2, Vector 4 */
void __ISR(TIMER_1_INT_VECTOR, ipl2) _Timer1Handler(void)
{
// clear the interrupt flag
mT1ClearIntFlag();
// .. things to do ..
Advanced
-page 173
-page 174
Advanced
12.0
This section contains a list of individual functions for Input Capture module and an example of
use of the functions. Functions may be implemented as macros.
12.1
OpenCapture1
OpenCapture2
OpenCapture3
OpenCapture4
OpenCapture5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
config
OpenCapture1(unsigned
OpenCapture2(unsigned
OpenCapture3(unsigned
OpenCapture4(unsigned
OpenCapture5(unsigned
int
int
int
int
int
config);
config);
config);
config);
config);
-page 175
None
Remarks:
Code Example:
CloseCapture1
CloseCapture2
CloseCapture3
CloseCapture4
CloseCapture5
-page 176
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
This function disables the Input Capture interrupt and then turns off the
module.The Interrupt Flag bit is also cleared.
Code Example:
CloseCapture1();
CloseCapture1(void);
CloseCapture2(void);
CloseCapture3(void);
CloseCapture4(void);
CloseCapture5(void);
ConfigIntCapture1
ConfigIntCapture2
ConfigIntCapture3
ConfigIntCapture4
ConfigIntCapture5
ConfigIntCapture6
ConfigIntCapture7
ConfigIntCapture8
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
config
ConfigIntCapture1(unsigned
ConfigIntCapture2(unsigned
ConfigIntCapture3(unsigned
ConfigIntCapture4(unsigned
ConfigIntCapture5(unsigned
int
int
int
int
int
config);
config);
config);
config);
config);
Return Value:
None
Remarks:
This function clears the Interrupt Flag bit and then sets the interrupt
priority and enables/disables the interrupt.
Code Example:
ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_1 |
IC_INT_SUB_PRIOR_3);
-page 177
-page 178
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
buffer
Return Value:
None
Remarks:
This function reads all the pending Input Capture buffers until the
buffers are empty indicated by the ICxCON<ICBNE> bit getting
cleared.
Code Example:
ReadCapture1(unsigned
ReadCapture2(unsigned
ReadCapture3(unsigned
ReadCapture4(unsigned
ReadCapture5(unsigned
int
int
int
int
int
*buffer);
*buffer);
*buffer);
*buffer);
*buffer);
This is the pointer to the locations where the data read from
the Input Capture buffers have to be stored.
12.2
Individual Macros
EnableIntIC1
EnableIntIC2
EnableIntIC3
EnableIntIC4
EnableIntIC5
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro sets Input Capture Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
EnableIntIC1;
DisableIntIC1
DisableIntIC2
DisableIntIC3
DisableIntIC4
DisableIntIC5
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro clears Input Capture Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
DisableIntIC4;
SetPriorityIntIC1
SetPriorityIntIC2
SetPriorityIntIC3
SetPriorityIntIC4
SetPriorityIntIC5
Description:
Include:
plib.h
Arguments:
config
-page 179
This macro sets Input Capture Interrupt Priority bits of Interrupt Priority
Control register.
Code Example:
SetPriorityIntIC4(IC_INT_PRIOR_5 |
IC_INT_SUB_PRIOR_2);
mIC1CaptureReady()
mIC2CaptureReady()
mIC3CaptureReady()
mIC4CaptureReady()
mIC4CaptureReady()
Description:
Include:
plib.h
Arguments:
None
Remarks:
Code Example:
if( mIC1CaptureReady() )
// we have capture(s) ready
mIC1ReadCapture()
mIC2ReadCapture()
mIC3ReadCapture()
mIC4ReadCapture()
mIC4ReadCapture()
-page 180
Description:
Include:
plib.h
Arguments:
None
Remarks:
Code Example:
if( mIC1CaptureReady() )
{
// we have capture(s) ready
capVal = mIC1ReadCapture();
}
12.3
Example of Use
#include <plib.h>
#define
#define
#define
#define
#define
FOSC
PB_DIV
PRESCALE
MSEC
T1_TICK
60E6
8
256
10E-3
(500 * MSEC * FOSC)/(PB_DIV * PRESCALE)
/////////////////////////////////////////////
/////////////////////////////////////////////
int main(void)
{
unsigned int CaptureTime;
//Clear interrupt flag
mIC1ClearIntFlag();
// Setup Timer 3
OpenTimer3(T3_ON | T1_PS_1_256, T1_TICK);
// Enable Input Capture Module 1
// - Capture Every edge
// - Enable capture interrupts
// - Use Timer 3 source
// - Capture rising edge first
OpenCapture1( IC_EVERY_EDGE | IC_INT_1CAPTURE | IC_TIMER3_SRC |
IC_FEDGE_RISE | IC_ON );
// Wait for Capture events
while( !mIC1CaptureReady() ) ;
//Now Read the captured timer value
while( mIC1CaptureReady() )
{
CaptureTime = mIC1ReadCapture();
//process data
// ...
}
CloseCapture1();
CloseTimer3();
while(1)
{}
}
-page 181
-page 182
13.0
This section contains a list of individual functions for Output Compare module and an example
of use of the functions. Functions may be implemented as macros.
13.1
Individual Functions
CloseOC1
CloseOC2
CloseOC3
CloseOC4
CloseOC5
Description:
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
None
Return Value:
None
Remarks:
This function disables the Output Compare interrupt and then turns off
the module. The Interrupt Flag bit is also cleared.
CloseOC1(void);
CloseOC2(void);
CloseOC3(void);
CloseOC4(void);
CloseOC5(void);
Source File:
Code Example:
CloseOC1();
-page 183
Include:
plib.h
Prototype:
void
void
void
void
void
Arguments:
config
ConfigIntOC1(unsigned
ConfigIntOC2(unsigned
ConfigIntOC3(unsigned
ConfigIntOC4(unsigned
ConfigIntOC5(unsigned
int
int
int
int
int
config);
config);
config);
config);
config);
Return Value:
None
Remarks:
This function clears the Interrupt Flag bit and then sets the interrupt
priority and enables/disables the interrupt.
Source File:
Code Example:
-page 184
ConfigIntOC1(OC_INT_ON | OC_INT_PRIOR_2 |
OC_INT_SUB_PRIOR_2);
OpenOC1
OpenOC2
OpenOC3
OpenOC4
OpenOC5
Description:
Include:
plib.h
Prototype:
Arguments:
config
value2);
value2);
value2);
value2);
value2);
Return Value:
value1
value2
None
-page 185
-page 186
Remarks:
Code Example:
OpenOC1(OC_ON | OC_TIMER2_SRC |
OC_PWM_FAULT_PIN_ENABLE, 0x80, 0x60);
ReadDCOC1PWM
ReadDCOC2PWM
ReadDCOC3PWM
ReadDCOC4PWM
ReadDCOC5PWM
Description:
This function reads the duty cycle from the Output Compare Secondary
register.
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
None
Return Value:
Remarks:
This function reads the duty cycle from the Output Compare Secondary
register (OCxRS) when Output Compare module is in PWM mode.
If not in PWM mode, the functions returns a value of -1.
Code Example:
int
int
int
int
int
ReadDCOC1PWM(void);
ReadDCOC2PWM(void);
ReadDCOC3PWM(void);
ReadDCOC4PWM(void);
ReadDCOC5PWM(void);
-page 187
This function reads the duty cycle registers when Output Compare
module is not in PWM mode.
Include:
plib.h
Prototype:
unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
-page 188
int
int
int
int
int
ReadRegOC1(unsigned
ReadRegOC2(unsigned
ReadRegOC3(unsigned
ReadRegOC4(unsigned
ReadRegOC5(unsigned
int
int
int
int
int
reg);
reg);
reg);
reg);
reg);
reg This indicates if the read should happen from the main or
secondary duty cycle registers of Output Compare module.
If reg is 1, then the contents of Main Duty Cycle register
(OCxR) is read.
If reg is 0, then the contents of Secondary Duty Cycle register
(OCxRS) is read.
Return Value:
Remarks:
The read of Duty Cycle register happens only when Output Compare
module is not in PWM mode. Else, a value of -1 is returned.
Code Example:
SetDCOC1PWM
SetDCOC2PWM
SetDCOC3PWM
SetDCOC4PWM
SetDCOC5PWM
Description:
Include:
outcompare.h
Prototype:
void
void
void
void
void
Arguments:
dutycycle
Return Value:
None
Remarks:
Code Example:
SetDCOC1PWM(dutycycle);
SetDCOC1PWM(unsigned
SetDCOC2PWM(unsigned
SetDCOC3PWM(unsigned
SetDCOC4PWM(unsigned
SetDCOC5PWM(unsigned
int
int
int
int
int
dutycycle);
dutycycle);
dutycycle);
dutycycle);
dutycycle);
-page 189
Include:
plib.h
Prototype:
Arguments:
-page 190
pulse_start,
pulse_start,
pulse_start,
pulse_start,
pulse_start,
pulse_start
pulse_stop
Return Value:
None
Remarks:
The Output Compare duty cycle registers (OCxR and OCxRS) will be
configured with new values only if the module is not in PWM mode.
Code Example:
pulse_start = 0x40;
pulse_stop = 0x60;
SetPulseOC1(pulse_start, pulse_stop);
13.2
Example of Use
#include <plib.h>
/* This is ISR corresponding to OC1 interrupt */
#pragma interrupt OC1Interrupt ipl2 vector 6
void OC1Interrupt(void)
{
IFS0bits.OC1IF = 0;
}
int main(void)
{
/* Holds the value at which OCx Pin to be driven high */
unsigned int pulse_start ;
/* Holds the value at which OCx Pin to be driven low */
unsigned int pulse_stop;
/* Turn off OC1 module */
CloseOC1;
/* Configure output compare1 interrupt */
ConfigIntOC1(OC_INT_PRIOR_5 | EXT_INT_SUB_PRI_2);
/* Configure OC1 module for required pulse width */
pulse_start = 0x40;
pulse_stop = 0x60;
PR2 = 0x80 ;
T2CON = 0x8000;
/* Configure Output Compare module to 'initialise OCx pin
low and generate continuous pulse'mode */
OpenOC1(OC_IDLE_CON | OC_TIMER2_SRC |
OC_CONTINUE_PULSE,
pulse_stop, pulse_start);
/* Generate continuous pulse till TMR2 reaches 0xff00 */
while(TMR2<= 0xff00);
asm("nop");
CloseOC1;
return 0;
}
-page 191
-page 192
14.0
SPI FUNCTIONS
This section provides a list and a description of the interface functions that are part of the SPI
API Peripheral Library.
14.1
Open Functions
OpenSPI1
OpenSPI2
Description:
Include:
plib.h
Prototype:
void OpenSPI1(unsigned
unsigned
void OpenSPI2(unsigned
unsigned
Arguments:
int
int
int
int
config1,
config2);
config1,
config2);
-page 193
Return Value:
None
Remarks:
Source File:
spi_open_spi1_lib.c
spi_open_spi2_lib.c
Code Example:
OpenSPI1(SPI_MODE32_ON|SPI_SMP_ON|MASTER_ENABLE_ON|S
EC_PRESCAL_1_1|PRI_PRESCAL_1_1, SPI_ENABLE);
14.2
Close Functions
-page 194
CloseSPI1
CloseSPI2
Description:
This routines disable the SPI modules and clear the interrupt bits.
Include:
plib.h
Prototype:
void CloseSPI1(void);
void CloseSPI2(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
CloseSPI1();
14.3
ConfigIntSPI1
ConfigIntSPI2
Description:
Include:
plib.h
Prototype:
Arguments:
-page 195
None
Remarks:
None
Source File:
plib.h
Code Example:
ConfigIntSPI1(SPI_FAULT_INT_EN|SPI_RX_INT_EN|SPI_INT
_PRI_0|SPI_INT_SUB_PRI_2);
ConfigIntSPI2(SPI_FAULT_INT_EN|SPI_TX_INT_EN|SPI_INT
_PRI_4|SPI_INT_SUB_PRI_2);
EnableIntSPI1
EnableIntSPI2
Description:
These macros enable the receive and transmit interrupts for SPI 1 and
2
Include:
plib.h
Prototype:
EnableIntSPI1
EnableIntSPI1
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
EnableIntSPI1;
EnableIntSPI2;
DisableIntSPI1
DisableIntSPI2
-page 196
Description:
These macros disable the receive and transmit interrupts for SPI 1 and
2
Include:
plib.h
Prototype:
DisableIntSPI1
DisableIntSPI2
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
plib.h
DisableIntSPI1
DisableIntSPI2
Code Example:
DisableIntSPI1;
DisableIntSPI2;
SetPriorityIntSPI1
SetPriorityIntSPI2
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
SetPriorityIntSPI1(SPI_INT_PRI_0);
SetPriorityIntSPI2(SPI_INT_PRI_3);
SetSubPriorityIntSPI1
SetSubPriorityIntSPI2
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
plib.h
Code Example:
SetSubPriorityIntSPI1(SPI_INT_SUB_PRI_3);
SetSubPriorityIntSPI2(SPI_INT_SUB_PRI_1);
-page 197
DataRdySPI1
DataRdySPI2
Description:
Include:
plib.h
Prototype:
int DataRdySPI1(void);
int DataRdySPI2(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
plib.h
Code Example:
int isDataAvlbl;
isDataAvlbl = DataRdySPI1();
TxBufFullSPI1
TxBufFullSPI2
Description:
These functions test if transmit buffer is full and determine if the data
can be written to the SPIBUF register without overwriting the previous,
unsent data..
Include:
plib.h
Prototype:
int TxBufFullSPI1(void);
int TxBufFullSPI2(void);
Arguments:
None
Return Value:
- true if SPI buffer is full and data cannot be written to device, in order to
be serialized
- false otherwise
Remarks:
None
Source File:
plib.h
Code Example:
if(!TxBufFullSPI1()){WriteSPI1('a');}
ReadSPI1
ReadSPI2
-page 198
Description:
This function will read single byte/half word/word from SPI receive
register.
Include:
plib.h
Prototype:
Arguments:
None
ReadSPI1 (Continued)
ReadSPI2
Return Value:
Remarks:
None
Source File:
plib.h
Code Example:
int data=ReadSPI1();
WriteSPI1
WriteSPI2
Description:
This function writes the data to be transmitted into the Transmit Buffer
(SPIxBUF) register.
Include:
plib.h
Prototype:
Arguments:
data
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
WriteSPI1(0x44332211);
getcSPI1
getcSPI2
Description:
This function waits for receive data to be available. It will then read
single byte/half word/word from the SPI channel.
Include:
plib.h
Prototype:
Arguments:
None
Remarks:
Return Value:
None
Source File:
spi_getc_spi1_lib.c
spi_getc_spi2_lib.c
Code Example:
int data=getcSPI1();
-page 199
This routine writes a single byte/half word/word to the SPI bus. It waits
so that it doesn't overwrite the previous untransmitted data.
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
putcSPI1(0xaa);
getsSPI1
getsSPI2
Description:
This routine reads a string from the SPI receive buffer. The number of
characters (bytes/half words/words) to be read is determined by
parameter 'length'.
Include:
plib.h
Prototype:
Arguments:
-page 200
int length,
int *rdptr,
int spi_data_wait);
int length,
int *rdptr,
int spi_data_wait);
length
rdptr
spi_data_wait
Remarks:
Return Value:
Source File:
spi_gets_spi1_lib.c
spi_gets_spi2_lib.c
Code Example:
putsSPI1
putsSPI2
Description:
Include:
plib.h
Prototype:
void putsSPI1(unsigned
unsigned
void putsSPI2(unsigned
unsigned
Arguments:
int
int
int
int
length,
*wrptr);
length,
*wrptr);
Remarks:
Return Value:
None
Source File:
spi_puts_spi1_lib.c
spi_puts_spi2_lib.c
Code Example:
14.5
14.5.1
SpiChnOpen
Description:
This function initializes the SPI channel and also sets the brg register.
Include:
plib.h
Prototype:
Arguments:
-page 201
Return Value:
None
Source File:
spi_chn_open_lib.c
Code Example:
SpiChnOpen(1,
SPICON_MSTEN|SPICON_SMP|SPICON_MODE32|SPICON_ON, 4);
SpiChnClose
-page 202
Description:
This function closes the SPI channel. Some previous error conditions
are cleared. Channel interrupts are disabled.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
spi_chn_close_lib.c
Code Example:
SpiChnClose(2);
SpiChnSetBrg,
mSpiChnSetBrg
Description:
This function/macro updates the values for the SPI channel baud rate
generator register
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
spi_chn_set_brg_lib.c
Code Example:
SpiChnChgMode
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
When changing mode, the function blocks until the current transfer, if
any, is completed.
Remarks:
None
Remarks:
Return Value:
None
Source File:
spi_chn_chg_mode_lib.c
Code Example:
SpiChnChgMode(1, 1, 1);
14.5.2
-page 203
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
spi_chn_data_rdy_lib.c
Code Example:
int isDataAvlbl=SpiChnDataRdy(1);
SpiChnGetC
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
spi_chn_getc_lib.c
Code Example:
int newData=SpiChnGetC(2);
SpiChnGetS
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
pBuff has to be a valid pointer to a buffer large enough to store all the
received characters
pBuff is considered to be 8/16/32 bits data pointer, according to the
current SPI mode
The function blocks waiting for the whole buffer to be received.
-page 204
Return Value:
Source File:
spi_chn_gets_lib.c
Code Example:
SpiChnTxBuffEmpty
Description:
This function reads the SPI channel transmit buffer empty condition.
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
spi_chn_tx_buff_empty_lib.c
Code Example:
int canTransmit=SpiChnTxBuffEmpty(1);
SpiChnPutC
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
spi_chn_putc_lib.c
Code Example:
SpiChnPutC(1, 0x1b);
SpiChnPutS
Description:
This function writes the specified number of 8/16/32 bit characters from
the specified buffer. It waits for Tx buffer empty so the characters are
not overwritten.
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
spi_chn_puts_lib.c
Code Example:
-page 205
SpiChnGetRov
Description:
This function reads the SPI channel overflow condition and clears it, if
required
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
spi_chn_get_rov_lib.c
Code Example:
14.5.3
SpiChnGetRovIntFlag
mSpiChnGetRovIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnClrRovIntFlag
mSpiChnClrRovIntFlag
-page 206
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnGetRxIntFlag
mSpiChnGetRxIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
plib.h
Code Example:
SpiChnClrRxIntFlag
mSpiChnClrRxIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnGetTxIntFlag
mSpiChnGetTxIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
plib.h
Code Example:
-page 207
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnGetIntFlag
mSpiChnGetIntFlag
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
plib.h
Code Example:
SpiChnClrIntFlags
mSpiChnClrIntFlags
-page 208
Description:
This function/macro clears all the SPI channel interrupt flags (Tx, Rx or
ovfl).
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
Code Example:
14.5.4
SpiChnRxIntEnable
mSpiChnRxIntEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnRxIntDisable
mSpiChnRxIntDisable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnTxIntEnable
mSpiChnTxIntEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
-page 209
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnRxTxIntEnable
mSpiChnRxTxIntEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnRxTxIntDisable
mSpiChnRxTxIntDisable
-page 210
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnFaultIntEnable
mSpiChnFaultIntEnable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
SpiChnFaultIntDisable
mSpiChnFaultIntDisable
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
Return Value:
None
Source File:
plib.h
Code Example:
14.5.5
SpiChnSetIntPriority
mSpiChnSetIntPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
None
Source File:
plib.h
-page 211
SpiChnGetIntPriority
mSpiChnGetIntPriority
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
plib.h
Code Example:
SpiChnGetIntSubPriority
mSpiChnGetIntSubPriority
-page 212
Description:
Include:
plib.h
Prototype:
Arguments:
Remarks:
None
Return Value:
Source File:
plib.h
Code Example:
int chn=2;
int currSPri=SpiChnGetIntSubPriority(chn);
int currSPri=mSpiChnGetIntSubPriority(2);
14.6
Example of Use
#include <plib.h>
// configuration settings
#pragma config POSCMOD = HS, FNOSC = PRIPLL
#pragma config PLLMUL = MUL_18, PLLIDIV = DIV_2
#pragma config FWDTEN = OFF
int main(void)
{
// init the transmit buffer
static const char txBuff[]="String of characters to be sent over \
the SPI channel";
//room for the receive buffer
static char rxBuff[sizeof(txBuff)];
int
ix;
int
rdData;
const char*pSrc;
char*pDst;
int
txferSize;
int
fail=0; // success flag
// configure the proper PB frequency and the number of wait states
SYSTEMConfigWaitStatesAndPB(72000000L);
CheKseg0CacheOn();// enable the cache for the best performance
mBMXDisableDRMWaitState(); // no wait states for RAM
// init the SPI chn 1 as master, 8 bits/character, frame master
// divide fpb by 2
SpiChnOpen(1, SPICON_MSTEN|SPICON_FRMEN|SPICON_SMP|SPICON_ON, 2);
txferSize=sizeof(txBuff);
ix=txferSize+1;
// transfer one extra word to give the slave the possibility
// to reply back the last sent word
pSrc=txBuff;
pDst=rxBuff;
while(ix--)
{
SpiChnPutC(1, *pSrc++);// send data on the master channel
rdData=SpiChnGetC(1);// get the received data
if(ix!=txferSize)
{
// skip the first received character, it's garbage
*pDst++=rdData;// store the received data
}
rdData=SpiChnGetC(2);// receive data on the slave channel
SpiChnPutC(2, rdData);// relay back data
}
// now let's check that the data was received ok
pSrc=txBuff;
pDst=rxBuff;
for(ix=0; ix<sizeof(txBuff); ix++)
{
if(*pDst++!=*pSrc++)
{
fail=1; // data mismatch
-page 213
-page 214
15.0
I2C FUNCTIONS
This section contains a list of individual functions for I2C module and an example of use of the
functions. Functions may be implemented as macros.
15.1
Individual Functions
CloseI2C1
CloseI2C2
Description:
Include:
plib.h
Prototype:
void CloseI2C1(void);
Arguments:
None
Return Value
None
Remarks:
This function disables the I2C module and clears the Master and Slave
Interrupt Enable and Flag bits.
Code Example:
CloseI2C1();
AckI2C1
AckI2C2
Description:
Include:
plib.h
Prototype:
void AckI2C1(void);
Arguments:
None
Return Value
None
Remarks:
Code Example:
AckI2C1();
DataRdyI2C1
DataRdyI2C2
Description:
Include:
plib.h
Prototype:
int DataRdyI2C1(void)
Arguments:
None
Return Value
Remarks:
Code Example:
if(!DataRdyI2C1());
IdleI2C1
IdleI2C2
Description:
Include:
plib.h
Prototype:
void IdleI2C1(void);
-page 215
-page 216
Arguments:
None
Return Value
None
Remarks:
This function will be in a wait state until Start Condition Enable bit, Stop
Condition Enable bit, Receive Enable bit, Acknowledge Sequence
Enable bit of I2C Control register and Transmit Status bit I2C Status
register are clear. The IdleI2C function is required since the hardware
I2C peripheral does not allow for spooling of bus sequence. The I2C
peripheral must be in Idle state before an I2C operation can be initiated
or write collision will be generated.
Code Example:
IdleI2C1();
MastergetsI2C1
MastergetsI2C2
Description:
This function reads predetermined data string length from the I2C bus.
Include:
plib.h
Prototype:
Arguments:
length
rdptr
i2c_data_wait This is the time-out count for which the module has
to wait before return.
If the time-out count is N, the actual time out would
be about (20 * N 1) core cycles.
Return Value
This function returns 0 if all bytes have been sent or number of bytes
read from I2C bus if its not able to read the data with in the specified
i2c_data_wait time out value
Remarks:
This routine reads a predefined data string from the I2C bus.
Code Example:
MasterputsI2C1
MasterputsI2C2
Description:
This function is used to write out a data string to the I2C bus.
Include:
plib.h
Prototype:
Arguments:
wrptr
Return Value
Remarks:
This function writes a string to the I2C bus until a null character is
reached. Each byte is written via a call to the MasterputcI2C
function. The actual called function body is termed MasterWriteI2C.
MasterWriteI2C and MasterputcI2C refer to the same function via
a #define statement in the plib.h
Code Example:
-page 217
Include:
plib.h
Prototype:
Arguments:
None
Return Value
The return value is the data byte read from the I2C bus.
Remarks:
Code Example:
MasterWriteI2C1
MasterWriteI2C2
Description:
This function is used to write out a single data byte to the I2C device.
Include:
plib.h
Prototype:
Arguments:
data_out
Return Value
Remarks:
This function writes out a single data byte to the I2C bus device. This
function performs the same function as MasterputcI2C.
Code Example:
MasterWriteI2C1(a);
NotAckI2C1
NotAckI2C2
-page 218
Description:
Include:
plib.h
Prototype:
void NotAckI2C1(void);
Arguments:
None
Return Value
None
Remarks:
Code Example:
NotAckI2C1();
OpenI2C1
OpenI2C2
Description:
Include:
plib.h
Prototype:
Arguments:
config1
-page 219
Return Value
None
Remarks:
This function configures the I2C Control register and I2C Baud Rate
Generator register.
Code Example:
OpenI2C1();
RestartI2C1
RestartI2C2
Description:
Include:
plib.h
Prototype:
void RestartI2C1(void);
Arguments:
None
Return Value
None
Remarks:
Code Example:
RestartI2C1();
SlavegetsI2C1
SlavegetsI2C2
Description:
This function reads pre-determined data string length from the I2C bus.
Include:
plib.h
Prototype:
Arguments:
rdptr
i2c_data_wait This is the time-out count for which the module has
to wait before return.
If the time-out count is N, the actual time out would
be about (20*N - 1) core clock cycles.
-page 220
Return Value
Remarks:
This routine reads a predefined data string from the I2C bus.
Code Example:
SlaveputsI2C1
SlaveputsI2C2
Description:
This function is used to write out a data string to the I2C bus.
Include:
plib.h
Prototype:
Arguments:
wrptr
Return Value
This function returns 0 if the null character was reached in the data
string.
Remarks:
This routine writes a data string out to the I2C bus until a null character
is reached.
Code Example:
SlaveReadI2C1
SlaveReadI2C2
Description:
This function is used to read a single byte from the I2C bus.
Include:
plib.h
Prototype:
Arguments:
None
Return Value
The return value is the data byte read from the I2C bus.
Remarks:
This function reads in a single byte from the I2C bus. This function
performs the same function as SlavegetcI2C.
Code Example:
SlaveWriteI2C1
SlaveWriteI2C2
Description:
This function is used to write out a single byte to the I2C bus.
Include:
plib.h
Prototype:
Arguments:
data_out
Return Value
None
Remarks:
This function writes out a single data byte to the I2C bus device. This
function performs the same function as SlaveputcI2C.
Code Example:
SlaveWriteI2C2(a);
-page 221
Include:
plib.h
Prototype:
void StartI2C1(void);
Arguments:
None
Return Value
None
Remarks:
Code Example:
StartI2C1();
StopI2C1
StopI2C2
Description:
Include:
plib.h
Prototype:
void StopI2C1(void);
Arguments:
None
Return Value
None
Remarks:
Code Example:
StopI2C1();
15.2
Individual Macros
EnableIntMI2C1
EnableIntMI2C2
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro sets Master I2C Enable bit of Interrupt Enable Control
register.
Code Example:
EnableIntMI2C1;
DisableIntMI2C1
DisableIntMI2C2
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro clears Master I2C Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
DisableIntMI2C1;
EnableIntBI2Cx
DisableIntBI2Cx
Description:
-page 222
EnableIntBI2Cx
DisableIntBI2Cx
Include:
plib.h
Arguments:
None
Remarks:
This macro sets or clears Bus Collision I2C Interrupt Enable bit of
Interrupt Enable Control register.
Code Example:
DisableIntBI2C1;
-page 223
Include:
plib.h
Prototype:
Arguments:
config
I2C2_INT_PRI_0
I2C2_INT_PRI_1
I2C2_INT_PRI_2
I2C2_INT_PRI_3
I2C2_INT_PRI_4
I2C2_INT_PRI_5
I2C2_INT_PRI_6
I2C2_INT_PRI_7
are mutually exclusive)
I2C2_SUB_INT_PRI_0
I2C2_SUB_INT_PRI_1
I2C2_SUB_INT_PRI_2
I2C2_SUB_INT_PRI_3
mutually exclusive)
Remarks:
This macro sets I2C Interrupt Priority bits of Interrupt Priority Control
register.
Code Example:
SetPriorityIntI2C1(I2C1_INT_PRI_2 |
I2C1_INT_SUB_PRI_3);
EnableIntSI2C1
EnableIntSI2C2
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro sets Slave I2C Enable bit of Interrupt Enable Control
register.
Code Example:
EnableIntSI2C1;
DisableIntSI2C1
DisableIntSI2C2
-page 224
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro clears Slave I2C Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
DisableIntSI2C1;
-page 225
Example of Use
#include <plib.h>
//
//
Input Divider
//
Multiplier
2x Divider
15x Multiplier
//
(CCLK/8)
#define Fsck375000
#define BRG_VAL (PBCLK/2/Fsck)
/////////////////////////////////////////////
/////////////////////////////////////////////
void i2c_wait(unsigned int cnt)
{
while(--cnt)
{
Nop();
Nop();
}
}
/////////////////////////////////////////////
/////////////////////////////////////////////
int main(void)
{
unsigned char SlaveAddress;
char i2cData[10];
int
DataSz;
//Enable channel
OpenI2C1( I2C_EN, BRG_VAL );
-page 226
int Index = 0;
while( DataSz )
{
MasterWriteI2C1( i2cData[Index++] );
IdleI2C1();//Wait to complete
DataSz--;
//ACKSTAT is 0 when slave acknowledge. if 1 then slave has not acknowledge the data.
if( I2C1STATbits.ACKSTAT )
break;
}
// wait for eeprom to complete write process. poll the ack status
while(1)
{
i2c_wait(10);
MasterWriteI2C1( i2cData[0] );
IdleI2C1();//Wait to complete
-page 227
i2cData[0] = (SlaveAddress << 1) | 0;//EEPROM Device Address and WR Command (to write the address)
i2cData[1] = 0x05;//eeprom location to read (high address byte)
i2cData[2] = 0x40;//eeprom location to read (low address byte)
DataSz = 3;
DataSz--;
//ACKSTAT is 0 when slave acknowledge. if 1 then slave has not acknowledge the data.
if( I2C1STATbits.ACKSTAT )
break;
}
-page 228
while(1) // Success
{}
-page 229
-page 230
16.0
UART FUNCTIONS
This section contains a list of individual functions for UART module and an example of use of the
functions. Functions may be implemented as macros.
16.1
Individual Functions
BusyUART1
BusyUART2
Description:
Include:
plib.h
Prototype:
int BusyUART1(void);
int BusyUART2(void);
Arguments:
None
Return Value:
Remarks:
This macro returns the status of the UART. This indicates if the UART is
busy in transmission as indicated by the UxSTA<TRMT> bit.
Code Example:
while(BusyUART1());
CloseUART1
CloseUART2
Description:
Include:
plib.h
Prototype:
void CloseUART1(void);
void CloseUART2(void);
Arguments:
None
Return Value:
None
Remarks:
This macro first turns off the UART module and then disables the UART
transmit and receive interrupts. The Interrupt Flag bits are also cleared.
Code Example:
CloseUART1();
-page 231
Include:
plib.h
Prototype:
Arguments:
config
-page 232
Return Value:
None
Remarks:
Code Example:
ConfigIntUART1(UART_RX_INT_EN | UART_TX_INT_DIS |
UART_ERR_INT_EN | UART_INT_PR0 | UART_INT_SUB_PR0);
DataRdyUART1
DataRdyUART2
Description:
Include:
plib.h
Prototype:
int DataRdyUART1(void);
int DataRdyUART2(void);
Arguments:
None
Return Value:
Remarks:
Code Example:
while(DataRdyUART1());
OpenUART1
OpenUART2
Description:
Include:
plib.h
Prototype:
void OpenUART1(unsigned
unsigned int config2,
void OpenUART2(unsigned
unsigned int config2,
Arguments:
config1
int config1,
unsigned int ubrg);
int config1,
unsigned int ubrg);
-page 233
-page 234
OpenUART1 (Continued)
OpenUART2
UART Receive Interrupt mode select
UART_INT_RX_BUF_FUL
UART_INT_RX_3_4_FUL
UART_INT_RX_CHAR
(These bit fields are mutually exclusive)
UART address detect enable/disable
UART_ADR_DETECT_EN
UART_ADR_DETECT_DIS
(These bit fields are mutually exclusive)
UART OVERRUN bit clear
UART_RX_OVERRUN_CLEAR
(These bit fields are mutually exclusive)
ubrg
Return Value:
None
Remarks:
This macro configures the UART transmit and receive sections and
sets the communication baud rate.
Code Example:
OpenUART1(UART_EN | UART_BRGH_FOUR,
UART_TX_PIN_NORMAL | UART_RX_EN | UART_TX_ENABLE,
123);
-page 235
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
Code Example:
WriteUART1
WriteUART2
-page 236
Description:
Include:
plib.h
Prototype:
Arguments:
data
Return Value:
None
Remarks:
This macro writes the data to be transmitted into the transmit buffer.
If 9-bit transmission is enabled, the 9-bit value is written into the
transmit buffer.
If 8-bit transmission is enabled, then upper byte is masked and then
written into the transmit buffer.
Code Example:
WriteUART1(a);
getsUART1
getsUART2
Description:
This function reads a string of data of specified length and stores it into
the buffer location specified.
Include:
plib.h
Prototype:
Arguments:
length
buffer
uart_data_wait
Return Value:
Remarks:
None
Code Example:
putsUART1
putsUART2
Description:
Include:
plib.h
Prototype:
Arguments:
buffer
Return Value:
None
Remarks:
This function writes the data to be transmitted into the transmit buffer
until NULL character is encountered.
Once the transmit buffer is full, it waits until data gets transmitted and
then writes the next data into the Transmit register.
Code Example:
putsUART1(Hello World!);
-page 237
putcUART1
putcUART2
Description:
UART1GetErrors
UART2GetErrors
Description:
Include:
plib.h
Prototype:
Arguments:
None.
Return Value:
Remarks:
Code Example:
errorValue = UART1GetErrors();
if (errorValue & 0x01 )// Overflow error
if (errorValue & 0x02 ) // Frame error
if (errorValue & 0x04 ) // Parity error
UART1ClearErrors
UART2ClearErrors
Description:
Include:
plib.h
Prototype:
void UART1ClearErrors(void);
void UART2ClearErrors(void);
Arguments:
None.
Return Value:
None.
Remarks:
Code Example:
-page 238
UART1ClearErrors();
16.2
Individual Macros
EnableIntU1RX
EnableIntU2RX
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro sets UART Receive Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
EnableIntU2RX;
EnableIntU1TX
EnableIntU2TX
Description:
Include:
plib.h
Arguments:
None
Remarks:
This macro sets UART Transmit Interrupt Enable bit of Interrupt Enable
Control register.
Code Example:
EnableIntU2TX;
DisableIntU1RX
DisableIntU2RX
Description:
Include:
plib.h
Arguments:
None
Remarks:
Code Example:
DisableIntU1RX;
-page 239
Include:
plib.h
Arguments:
None
Remarks:
Code Example:
DisableIntU1TX;
SetPriorityIntU1
SetPriorityIntU2
Description:
Include:
plib.h
Arguments:
priority
Priority Level
UART_INT_PR0
UART_INT_PR1
UART_INT_PR2
UART_INT_PR3
UART_INT_PR4
UART_INT_PR5
UART_INT_PR6
UART_INT_PR7
Remarks:
This macro sets UART Interrupt Priority bits of Interrupt Priority Control
register.
Code Example:
SetPriorityIntU1(UART_INT_PR3);
SetSubPriorityIntU1
SetSubPriorityIntU2
Description:
Include:
plib.h
Arguments:
sub_priority
Sub Priority Level
UART_INT_SUB_PR0
UART_INT_SUB_PR1
UART_INT_SUB_PR2
UART_INT_SUB_PR3
-page 240
Remarks:
This macro sets UART Interrupt Sub Priority bits of Interrupt Priority
Control register.
Code Example:
SetSubPriorityIntU1(UART_INT_SUB_PR3);
16.3
Example of Use
UART1SendBreak
UART2SendBreak
Description:
Include:
plib.h
Prototype:
void UART1SendBreak(void);
void UART2SendBreak(void);
Arguments:
None.
Return Value:
None.
Remarks:
Code Example:
UART1SendBreak();
UART1EnableAutoAddr
UART2EnableAutoAddr
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None.
Remarks:
Code Example:
UART1EnableAutoAddr(0x18);
-page 241
-page 242
17.0
PMP FUNCTIONS
The PIC32MX PMP library consists of functions and macros supporting common configuration
and control features.
PMP Common Operations
mPMPOpen
mPMPClose
mPMPEnable
mPMPDisable
mPMPIdleStop
mPMPIdleContinue
PMP Master Port Operations
PMPSetAddress
PMPMasterRead
mPMPMasterReadByte
mPMPMasterReadWord
PMPMasterReadByteBlock
PMPMasterReadWordBlock
PMPMasterWrite
PMPMasterWriteByteBlock
PMPMasterWriteWordBlock
mIsPMPBusy
mPMPGetBusyFlag
PMP Slave Port Operations
mPMPSlaveRead
PMPSlaveReadBuffer
PMPSlaveReadBuffers
mPMPSlaveWrite
PMPSlaveWriteBuffer
PMPSlaveWriteBuffers
mPMPGetBufferFullFlags
mIsPMPSlaveBufferFull
mPMPGetBufferEmptyFlags
mIsPMPSlaveBufferEmpty
mIsPMPSlaveBufferOverflow
mPMPClearBufferOverflow
mIsPMPSlaveBufferUnderflow
mPMPClearBufferUnderflow
Advanced
-page 243
mPMPOpen
Description:
Include:
plib.h
Prototype:
Arguments:
ctrl
-page 244
Advanced
mPMPOpen (Continued)
PMP read and write polarity
PMP_WRITE_POL_HI
PMP_WRITE_POL_LO
PMP_READ_POL_HI
PMP_READ_POL_LO
(These bit fields are mutually exclusive)
mode
Advanced
-page 245
intr
-page 246
Advanced
mPMPOpen (Continued)
PMP interrupt on/off
PMP_INT_ON
PMP_INT_OFF
(These bit fields are mutually exclusive)
PMP interrupt priorities
PMP_INT_PRI_7
PMP_INT_PRI_6
PMP_INT_PRI_5
PMP_INT_PRI_4
PMP_INT_PRI_3
PMP_INT_PRI_2
PMP_INT_PRI_1
PMP_INT_PRI_0
(These bit fields are mutually exclusive)
Return Value:
None.
Remarks:
This function clears PMP interrupt flag, configures the PMP module
and interrupt priority then enables the module.
Code Example:
(PMP_ON | PMP_IDLE_CON |\
PMP_MUX_DATA8_LOWER |\
PMP_READ_WRITE_EN | \
PMP_CS2_CS1_EN |\
PMP_LATCH_POL_HI |\
PMP_CS2_POL_LO | PMP_CS1_POL_LO |\
PMP_WRITE_POL_LO | PMP_READ_POL_LO)
#define MODE
(PMP_IRQ_OFF | PMP_AUTO_ADDR_OFF |\
PMP_DATA_BUS_8 | PMP_MODE_MASTER2 |\
PMP_WAIT_BEG_3 | PMP_WAIT_MID_7 |\
PMP_WAIT_END_3 )
#define PORT
(PMP_PEN_ALL)
#define INT
(PMP_INT_ON | PMP_INT_PRI_4)
Advanced
-page 247
Include:
plib.h
Prototype:
void mPMPClose(void);
Arguments:
None
Return Value:
None
Remarks:
This function clears the PMP interrupt flag, disables the PMP module
and interrupt.
Code Example:
mPMPClose();
mPMPEnable
Description:
Include:
plib.h
Prototype:
void mPMPEnable(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mPMPEnable();
mPMPDisable
-page 248
Description:
Include:
plib.h
Prototype:
void mPMPDisable(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mPMPDisable();
Advanced
mPMPIdleStop
Description:
This macro configures the PMP to stop operating when cpu enters idle
mode
Include:
plib.h
Prototype:
void mPMPIdleStop(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
mPMPIdleStop();
mPMPIdleContinue
Description:
This macro configures the PMP to continue operating when cpu enters
idle mode
Include:
plib.h
Prototype:
void mPMPIdleContinue(void);
Arguments:
None
Return Value:
None
Remarks:
Code Example:
17.2
mPMPIdleContinue();
PMPSetAddress
Description:
This function sets the address that will appear on the PMP bus when a
master read or write operation is performed.
Include:
plib.h
Prototype:
Arguments:
address
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to updating the PMADDRS register.
Code Example:
void PMPSetAddress(0x4200);
Advanced
-page 249
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to reading the PMDIN register.
Note that the read data obtained from the PMDIN register is actually the
value latched from the previous read operation. Hence, the first user
read will be a dummy read to initiate the first bus read and fill the read
register.
Depending on the PMP mode, the data could be 8-bit or 16-bit,
however, the value returned is always 32-bits wide. For example, in 8bit mode, a value of 0xFF read from an external device will be returned
as 0x000000FF. Likewise, in 16-bit mode, a value of 0xFFFF read from
an external device will be returned as 0x0000FFFF.
See mPMPMasterReadByte and mPMPMasterReadWord macros
below if casting the return value to a specific size is required.
Code Example:
/* example */
unsigned int ReadValue;
ReadValue = PMPMasterRead();
/* example using casting */
unsigned char ReadValue8;
unsigned short ReadValue16;
ReadValue8 = (unsigned char) PMPMasterRead();
ReadValue16 = (unsigned short) PMPMasterRead();
mPMPMasterReadByte
-page 250
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
unsigned char
Remarks:
Code Example:
Advanced
mPMPMasterReadWord
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
unsigned short
Remarks:
Code Example:
PMPMasterReadByteBlock
Description:
This function reads a block of 8-bit (byte) data from an external device.
Include:
plib.h
Prototype:
Arguments:
address
bytes
pDest
.
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to reading a block of data. This
function is intended for use when the PMP is interfaced to an 8-bit
external device.
Code Example:
Advanced
-page 251
Include:
plib.h
Prototype:
Arguments:
pDest
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to reading a block of data. This
function is intended for use when the PMP is interfaced to an 16-bit
external device.
Code Example:
PMPMasterWrite
Description:
Include:
plib.h
Prototype:
Arguments:
value
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to writing to the PMDIN register.
This function can be used when the PMP is interfaced to either 8-,16-bit
external device.
Code Example:
-page 252
Advanced
PMPMasterWriteByteBlock
Description:
Include:
plib.h
Prototype:
Arguments:
pSrc
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to reading a block of data. This
function is intended for use when the PMP is interfaced to an 8-bit
external device.
Code Example:
Advanced
-page 253
Include:
plib.h
Prototype:
Arguments:
pSrc
Return Value:
None
Remarks:
This function polls the PMP Busy flag to ensure any previous read or
write operation has completed prior to reading a block of data. This
function is intended for use when the PMP is interfaced to an 16-bit
external device.
Code Example:
mIsPMPBusy
-page 254
Description:
This macro provides the state of the PMP module busy flag
Include:
plib.h
Prototype:
void mIsPMPBusy(void);
Arguments:
None
Return Value:
None
Remarks:
Notes
Code Example:
while(mIsPMPBusy());
Advanced
mPMPGetBusyFlag
Description:
This macro provides the state of the PMP module busy flag
Include:
plib.h
Prototype:
void mIsPMPBusy(void);
Arguments:
None
Return Value:
None
Remarks:
Notes
Code Example:
while(mIsPMPBusy());
Advanced
-page 255
mPMPSlaveRead
Description:
Include:
plib.h
Prototype:
void mPMPSlaveRead(void);
Arguments:
None
Return Value:
None
Remarks:
When operating in legacy slave mode, this macro provides the value in
the PMPDIN register
.
Notes
This macro does not check the status of the PMSTAT.IBF (input
buffer full) bit prior to reading the PMDIN register. It is recommended that the user verify PMSTAT<IBF> = 1 prior to reading the
PMDIN register.
If an external master write occurs before the current contents of
the PMDIN register is performed, the IBOV flag will be set, indicating an overflow. This function does not check or modify the IBOV
bit. Therefore the user should check for an overflow condition.
Code Example:
PMPSlaveReadBuffer
-page 256
Description:
Include:
plib.h
Prototype:
Arguments:
buf
Return Value:
Remarks:
Code Example:
Advanced
PMPSlaveReadBuffers
Description:
Include:
plib.h
Prototype:
Arguments:
pDest
Return Value:
None
Remarks:
When operating in buffered slave mode, this function reads all 4 slave
data input buffers and copies to user memory specified by pointer.
Code Example:
mIsPMPSlaveBufferFull
Description:
This macro provides the state of the slave Input Buffer Full status flag
Include:
plib.h
Prototype:
void mIsPMPSlaveBufferFull(void);
Arguments:
None
Return Value:
None
Remarks:
Notes
Code Example:
while(!mIsPMPSlaveBufferFull());
Advanced
-page 257
This macro provides the state of individual slave Input Buffer Full status
flags
Include:
plib.h
Prototype:
Arguments:
buf
Remarks:
Notes
Code Example:
mPMPGetBufferFullFlags(BUF0);
mIsPMPSlaveBufferOverflow
Description:
This macro provides the state of the slave Input Buffer Overflow flag
Include:
plib.h
Prototype:
void mIsPMPSlaveBufferOverflow(void);
Arguments:
None
Remarks:
Notes
Code Example:
if(mIsPMPSlaveBufferOverflow());
mPMPClearBufferOverflow
Description:
Include:
plib.h
Prototype:
void mPMPClearBufferOverflow(void);
Arguments:
None
Remarks:
Notes
Code Example:
mPMPClearBufferOverflow();
mPMPSlaveWrite
-page 258
Description:
Include:
plib.h
Prototype:
Advanced
mPMPSlaveWrite (Continued)
Arguments:
value
Return Value:
None
Remarks:
When operating in legacy slave mode, this function writes the data
value to the PMDOUT buffer register.
Notes
This function does not check the status of the PMSTAT.OBE (output
buffer empty) bit prior to writing to the PMDOUT register. Therefore the
user should check PMSTAT<OBE> bit = 1 prior to writing the PMDOUT
register.
Code Example:
PMPSlaveWriteBuffer
Description:
Include:
plib.h
Prototype:
Arguments:
buf
value
Return Value:
None
Remarks:
Code Example:
Advanced
-page 259
Include:
plib.h
Prototype:
Arguments:
pSrc
Return Value:
None
Remarks:
Code Example:
mIsPMPSlaveBufferEmpty
Description:
This macro provides the state of the slave Output Buffer Empty status
flag
Include:
plib.h
Prototype:
void mIsPMPSlaveBufferEmpty(void);
Arguments:
None
Remarks:
Notes
Code Example:
-page 260
if(mIsPMPSlaveBufferEmpty());
....
else
....
Advanced
mPMPGetBufferEmptyFlags
Description:
This macro provides the state of individual slave Output Buffer Empty
status flags
Include:
plib.h
Prototype:
void mPMPGetBufferEmptyFlags(void);
Arguments:
None
Remarks:
Notes
Code Example:
mPMPGetBufferEmptyFlags(BUF3);
mIsPMPSlaveBufferUnderflow
Description:
This macro provides the state of the slave Output Buffer Underflow
status flag
Include:
plib.h
Prototype:
void mIsPMPSlaveBufferUnderflow(void);
Arguments:
None
Remarks:
Notes
Code Example:
if(mIsPMPSlaveBufferUnderflow());
mPMPClearBufferUnderflow
Description:
Include:
plib.h
Prototype:
void mPMPClearBufferUnderflow(void);
Arguments:
None
Remarks:
Notes
Code Example:
PMPClearBufferUnderflow();
Advanced
-page 261
Example of Use
PMP_MODE
PMP_PORT
PMP_ADDR
PMP_INT
PMP_READ_POL_LO | PMP_WRITE_POL_LO |\
PMP_CS1_POL_LO
PMP_MODE_SLAVE
0x0000
0x0000
PMP_INT_PRI_3 | PMP_INT_ON
-page 262
Advanced
19.1
RTCC FUNCTIONS
This document provides a list and a description of the interface functions that are part of the RTCC API Peripheral
Library. It is intended as a quick reference to the user of the RTCC API. So, it is a complete specification of all the functions provided as well as being a guide to using these functions.
RtccInit
Description:
The function initializes the RTCC device. It starts the RTCC clock, enables the RTCC and disables RTCC write. Disables the Alarm and the OE. Clears the alarm interrupt flag.
Include:
plib.h
Prototype:
rtccRes RtccInit(void);
Arguments:
None
Return Value:
Remarks:
This function has to be called before using RTCC module services. It usually takes 4x256 clock
cycles (approx 31.2 ms) for the oscillator signal to be available to the RTCC. The user must
make sure that the clock is actually running using RtccGetClkStat() before expecting the RTCC
to count.
Source File:
rtcc_init_lib.c
Coding Example:
RtccOpen
Description:
The function initializes the RTCC device. It starts the RTCC clock, sets the desired time and
calibration and enables the RTCC. Disables the Alarm and the OE and further RTCC writes.
Clears the alarm interrupt flag..
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
This function is usually called after RtccInit() as we are sure that the RTCC clock is running and
is stable, i.e. RtccGetClkStat() returns RTCC_CLK_ON.
Source File:
rtcc_open_lib.c
Coding Example:
RtccShutdown
Description:
The function shutdowns the RTCC device. It stops the RTCC clock, sets the RTCC Off and
disables RTCC write. Disables the Alarm and the OE. Clears the alarm interrupt flag.
Include:
plib.h
Prototype:
void RtccShutdown(void);
Arguments:
None
Return Value:
None
Remarks:
After using this function RtccInit() has to be called again to be able to use the RTCC module
services.
Source File:
rtcc_shutdown_lib.c
Coding Example:
RtccShutdown ();
These functions deal with the setting and retrieving of the RTCC current time and alarm time.
RtccSetTime
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
- The write is successful only if Wr Enable is set. The function will enable the write itself, if
needed.
- The device could be stopped in order to safely perform the update of the RTC time register.
However, the device status will be restored but the routine won't wait for the CLK to be running
before returning. User has to check RtccGetClkStat() (will take approx 30us).
- The routine could disable the interrupts for a very short time to be able to update the time
and date registers.
Source File:
rtcc_set_time_lib.c
Coding Example:
RtccGetTime
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
The current value of the time which can be safely casted to an rtccTime structure.
Remarks:
- The function makes sure that the read value is valid. It avoids waiting for the RTCSYNC to be
clear by performing successive reads.
Source File:
rtcc.h
Coding Example:
RtccSetDate
Description:
Include:
plib.h
Prototype:
Arguments:
dt - the date value to be set containing the valid fields of a rtccDate structure:
- wday:BCD codification, 00-06
- mday: BCD codification, 01-31
- mon: BCD codification, 01-12
- year: BCD codification, 00-99
Return Value:
None
Remarks:
- The write is successful only if Wr Enable is set. The function will enable the write itself, if
needed.
- The device could be stopped in order to safely perform the update of the RTC time register.
However, the device status will be restored but the routine won't wait for the CLK to be running
before returning. User has to check RtccGetClkStat() (will take approx 30us).
- The routine could disable the interrupts for a very short time to be able to update the time and
date registers.
Source File:
rtcc_set_date_lib.c
Coding Example:
RtccGetDate
Description:
The function returns the current date of the RTCC device. Can be safely cast into rtccDate.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
The function makes sure that the read value is valid. It avoids waiting for the RTCSYNC to be
clear by performing successive reads.
Source File:
rtcc.h
Coding Example:
RtccSetTimeDate
Description:
The function sets the current time and date in the RTCC device.
Include:
plib.h
Prototype:
Arguments:
tm - the time value to be set, a valid rtccTime structure having proper halues:
- sec:BCD codification, 00-59
- min: BCD codification, 00-59
- hour: BCD codification, 00-24
dt - the date value to be set, a valid rtccDate structure having proper values:
- wday:BCD codification, 00-06
- mday: BCD codification, 01-31
- mon: BCD codification, 01-12
- year: BCD codification, 00-99
Return Value:
None
Remarks:
- The write is successful only if Wr Enable is set. The function will enable the write itself, if
needed.
- The device could be stopped in order to safely perform the update of the RTC time register.
However, the device status will be restored but the routine won't wait for the CLK to be running
before returning. User has to check RtccGetClkStat() (will take approx 30us).
- The routine could disable the interrupts for a very short time to be able to update the time and
date registers.
Source File:
rtcc_set_time_date_lib.c
Coding Example:
RtccGetTimeDate
Description:
The function updates the user supplied union/structures with the current time and date of the
RTCC device.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
- The function makes sure that the read value is valid. It avoids waiting for the RTCSYNC to be
clear by performing successive reads.
Source File:
rtcc.h
Coding Example:
RtccSetAlarmTime
Description:
The function sets the current alarm time in the RTCC device.
Include:
plib.h
Prototype:
Arguments:
tm - the alarm time to be set, a valid rtccTime structure having proper values:
- sec:BCD codification, 00-59
- min: BCD codification, 00-59
- hour: BCD codification, 00-24
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
ALRMTIME register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
Source File:
rtcc_set_alarm_time_lib.c
Coding Example:
mRtccGetAlarmTime
Description:
The macro returns the current alarm time of the RTCC device.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
the current alarm time, a value that can be safely cast into a rtccTime union:
- sec:BCD codification, 00-59
- min:BCD codification, 00-59
- hour:BCD codification, 00-24
Remarks:
None
Source File:
rtcc.h
Coding Example:
RtccSetAlarmDate
Description:
Include:
plib.h
Prototype:
Arguments:
dt - value of the alarm date, a valid rtccDate formatted structure having proper values:
- wday:BCD codification, 00-06
- mday: BCD codification, 01-31
- mon: BCD codification, 01-12
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
ALRMDATE register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
- Note that the alarm date does not contain a year field.
Source File:
rtcc_set_alarm_date_lib.c
Coding Example:
mRtccGetAlarmDate
Description:
The macro returns the current alarm date of the RTCC device.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
RtccSetAlarmTimeDate
Description:
The function sets the current alarm time and date in the RTCC device.
Include:
plib.h
Prototype:
Arguments:
tm - the alarm time to be set, a valid rtccTime structure having proper values:
- sec:BCD codification, 00-59
- min: BCD codification, 00-59
- hour: BCD codification, 00-24
dt - the alarm date to be set, a valid rtccDate structure having proper values:
- wday:BCD codification, 00-06
- mday: BCD codification, 01-31
- mon: BCD codification, 01-12
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
ALRMTIME, ALRMDATE registers.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC
needed.
- Note that the alarm time does not contain a year field.
Source File:
rtcc_set_alarm_time_date_lib.c
Coding Example:
RtccGetAlarmTimeDate
Description:
The function updates the user supplied union/structures with the current alarm time and date of
the RTCC device.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
RtccWeekDay
Description:
The function calculates the week of the day for new style dates, beginning at 14 Sep 1752.
Based on an algorithm by Lewis Carroll.
Include:
plib.h
Prototype:
Arguments:
Return Value:
Remarks:
None
Source File:
rtcc_weekday_lib.c
Coding Example:
RtccAlarmEnable
Description:
Include:
plib.h
Prototype:
void RtccAlarmEnable(void);
Arguments:
None
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
RTCALRM register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
Source File:
rtcc_alarm_enable_lib.c
Coding Example:
RtccAlarmEnable();
RtccAlarmDisable
Description:
Include:
plib.h
Prototype:
void RtccAlarmDisable(void);
Arguments:
None
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
RTCALRM register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
Source File:
rtcc_alarm_disable_lib.c
Coding Example:
RtccAlarmDisable();
RtccGetAlarmEnable
Description:
The function returns the current alarm status of the RTCC device.
Include:
plib.h
Prototype:
int RtccGetAlarmEnable(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isAlrmEnabled=RtccGetAlarmEnable();
RtccChimeEnable
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
RTCALRM register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
Source File:
rtcc_chime_enable_lib.c
Coding Example:
RtccChimeEnable();
RtccChimeDisable
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
RTCALRM register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC needed.
Source File:
rtcc_chime_disable_lib.c
Coding Example:
RtccChimeDisable();
RtccGetChimeEnable
Description:
Include:
plib.h
Prototype:
int RtccGetChimeEnable(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isChimeEnabled=RtccGetChimeEnable();
RtccSetAlarmRpt
Description:
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
- The function might wait for the proper Alarm window to safely perform the update of the
RTCALRM register.
- Interrupts are disabled shortly when properly probing the RTCSYNC/ALRMSYNC
needed.
Source File:
rtcc_set_alarm_rpt_lib.c
Coding Example:
RtccSetAlarmRpt(RTCC_RPT_MIN);
RtccGetAlarmRpt
Description:
Include:
plib.h
Prototype:
rtccRepeat RtccGetAlarmRpt(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
rtccRepeat rptAlrm=RtccGetAlarmRpt();
RtccSetAlarmRptCount
Description:
Include:
plib.h
Prototype:
Arguments:
rpt- value of the desired alarm repeat count, less then 256
The number of alarm triggers will be rptCnt+1:
- one alarm trigger if rptCnt==0
- ....
- 256 alarm triggers if rptCnt=255
Return Value:
None
Remarks:
Source File:
rtcc_set_alarm_rpt_count_lib.c
Coding Example:
RtccSetAlarmRptCount(10);
RtccGetAlarmRptCount
Description:
Include:
plib.h
Prototype:
int RtccGetAlarmRptCount(void);
Arguments:
None
Return Value:
Remarks:
The reading is affected by the sttatus of RTCALRM.ALRMSYNC bit. Double readings are performed.
Source File:
rtcc.h
Coding Example:
int alrmRptCnt=RtccGetAlarmRptCount();
RtccEnable
Description:
Include:
plib.h
Prototype:
rtccRes RtccEnable(void)
Arguments:
None
Return Value:
Remarks:
- The write operations have to be enabled in order to be able to toggle the ON control bit. Otherwise the function will fail. See RtccWrEnable() function.
- The function doesn't wait for the RTC clock to be on.
Source File:
rtcc_enable_lib.c
Coding Example:
rtccRes clkStat=RtccEnable();
RtccDisable
Description:
Include:
plib.h
Prototype:
int RtccDisable(void)
Arguments:
None
Return Value:
Remarks:
- The write operations have to be enabled in order to be able to toggle the ON control bit. Otherwise the function will fail. See RtccWrEnable() function.
- When ON control bit is set to 0, RTCCON.RTCSYNC, RTCCON.HALFSEC and RTCCON.RTCOE are asynchronously reset.
- The function waits for the RTC clock to be off.
Source File:
rtcc_disable_lib.c
Coding Example:
int isDisabled=RtccDisable();
mRtccGetEnable
Description:
The macro returns the enabled/disabled status of the RTCC module (i.e. the RTCCON.ON bit
anded with RTCCLKON).
Include:
plib.h
Prototype:
int mRtccGetEnable(void)
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isEnabled=mRtccGetEnable();
RtccGetClkStat
Description:
The function returns the status of the RTCC clock (the RTCCON.ON bit anded with RTCCLKON.
Include:
plib.h
Prototype:
rtccRes RtccGetClkStat(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
RtccSetCalibration
Description:
The function updates the value that the RTCC uses in the auto-adjust feature, once every
minute. The drift value acts as a signed value, [-512, +511], 0 not having any effect.
Include:
plib.h
Prototype:
Arguments:
drift- value to be added/subtracted to perform calibration. The drift value acts as a signed
value, [-512, +511], 0 not having any effect.
Return Value:
None
Remarks:
- Writes to the RTCCON.CAL[9:0] register should only occur when the timer is turned off or
immediately or after the edge of the seconds pulse (except when SECONDS=00 - due to the
possibility of the auto-adjust event). In order to speed-up the process, the API function performs the reading of the HALFSEC field.
- The function may block for half a second, worst case, when called at the start of the minute.
- A write to the SECONDS value resets the state of the calibration and the prescaler. If calibration just occurred, it will occur again at the prescaler rollover.
- Interrupts can not be disabled for such a long period. However, long interrupt routines can
interfere with the proper functioning of the device. Care must be taken.
Source File:
rtcc_set_calibration_lib.c
Coding Example:
RtccSetCalibration (200);
mRtccGetCalibration
Description:
The macro returns the value that the RTCC uses in the auto-adjust feature, once every
minute. The calibration value is a signed 10 bits value, [-512, +511].
Include:
plib.h
Prototype:
int mRtccGetCalibration(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int currCal=mRtccGetCalibration();
RtccWrEnable
Description:
The function enables the updates to the RTCC time registers and ON control bit.
Include:
plib.h
Prototype:
void RtccWrEnable();
Arguments:
None
Return Value:
None
Remarks:
- The write can be enabled by performing a specific unlock sequence. In order to succeed, this
sequence need not be interrupted by other memory accesses (DMA transfers, interrupts, etc).
- Interrupts and DMA transfers that might disrupt the write unlock sequence are disabled
shortly for properly unlocking the device.
Source File:
rtcc_wr_enable_lib.c
Coding Example:
RtccWrEnable ();
mRtccWrDisable
Description:
The macro performs the system lock sequence so that further updates to the RTCC time registers and ON control bit are disabled.
Include:
plib.h
Prototype:
void mRtccWrDisable();
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccWrDisable ();
mRtccGetWrEnable
Description:
The macro returns the current status of the RTCC write enable bit.
Include:
plib.h
Prototype:
int mRtccGetWrEnable(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isWrEnabled=mRtccGetWrEnable();
mRtccGetSync
Description:
The macro returns the current status of the RTCC Sync bit.
Include:
plib.h
Prototype:
int nRtccGetSync(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isSync=mRtccGetSync();
mRtccGetHalfSecond
Description:
The macro returns the current status of the RTCC HalfSec bit.
Include:
plib.h
Prototype:
int mRtccGetHalfSecond(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int is2HalfSec=mRtccGetHalfSecond();
mRtccGetAlrmSync
Description:
The macro returns the current status of the RTCALRM ALRMSYNC bit.
Include:
plib.h
Prototype:
int mRtccGetAlrmSync(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isAlrmSync=mRtccGetAlrmSync();
mRtccSelectSecPulseOutput
Description:
The macro selects the seconds clock pulse as the function of the RTCC output pin.
Include:
plib.h
Prototype:
void mRtccSelectSecPulseOutput(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc.h
Coding Example:
mRtccSelectSecPulseOutput();
mRtccSelectAlarmPulseOutput
Description:
The macro selects the alarm pulse as the function of the RTCC output pin.
Include:
plib.h
Prototype:
void mRtccSelectAlarmPulseOutput(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc.h
Coding Example:
mRtccSelectAlarmPulseOutput ();
RtccAlarmPulseHigh
Description:
The function sets the initial value of the output Alarm Pulse to logic 1.
Include:
plib.h
Prototype:
void RtccAlarmPulseHigh(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc_alarm_pulse_high_lib.c
Coding Example:
RtccAlarmPulseHigh ();
RtccAlarmPulseLow
Description:
The function sets the initial value of the output Alarm Pulse to logic 0.
Include:
plib.h
Prototype:
void RtccAlarmPulseLow(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc_alarm_pulse_low_lib.c
Coding Example:
RtccAlarmPulseLow ();
RtccAlarmPulseToggle
Description:
Include:
plib.h
Prototype:
void RtccAlarmPulseToggle(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc_alarm_pulse_toggle_lib.c
Coding Example:
RtccAlarmPulseToggle ();
mRtccGetAlarmPulse
Description:
The macro returns the current state of the output Alarm Pulse.
Include:
plib.h
Prototype:
int mRtccGetAlarmPulse(void);
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
int alrmPulse=mRtccGetAlarmPulse();
mRtccOutputEnable
Description:
Include:
plib.h
Prototype:
void mRtccOutputEnable(void);
Arguments:
None
Return Value:
None
Remarks:
Source File:
rtcc.h
Coding Example:
mRtccOutputEnable ();
mRtccOutputDisable
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccOutputDisable ();
mRtccGetOutputEnable
Description:
The macro returns the enabled/disabled status of the RTCC Output pin.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isOutEnabled=mRtccGetOutputEnable();
mRtccGetIntFlag
Description:
This macro reads the interrupt controller to check if the RTCC interrupt flag is set
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccClrIntFlag
Description:
This macro clears the RTCC event flag in the interrupt controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccClrIntFlag ();
mRtccEnableInt
Description:
This macro enables the RTCC event interrupts in the INT controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccEnableInt ();
mRtccDisableInt
Description:
This macro disables the RTCC event interrupts in the INT controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccDisableInt ();
mRtccGetIntEnable
Description:
This macro returns the status of the RTCC interrupts in the INT controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int isRtccIntEnabled=mRtccGetIntEnable();
mRtccSetIntPriority
Description:
This macro sets the RTCC event interrupt priority and sub-priority in the interrupt controller.
Include:
plib.h
Prototype:
Arguments:
Return Value:
None
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccSetIntPriority(5, 3);
mRtccGetIntPriority
Description:
This macro returns the RTCC event interrupt priority in the interrupt controller.
Include:
plib.h
Prototype:
int mRtccGetIntPriority(void);
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
int currPri=mRtccGetIntPriority();
mRtccGetIntSubPriority
Description:
This macro returns the RTCC event interrupt sub-priority in the interrupt controller.
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
Remarks:
None
Source File:
rtcc.h
Coding Example:
mRtccFreezeEnable
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
The Freeze control bit has no significance, unless the processor is under debugger control.
The FRZ bit reads always 0, unless in debug mode.
Source File:
rtcc.h
Coding Example:
mRtccFreezeEnable ();
mRtccFreezeDisable
Description:
Include:
plib.h
Prototype:
Arguments:
None
Return Value:
None
Remarks:
The Freeze control bit has no significance, unless the processor is under debugger control.
The FRZ bit reads always 0, unless in debug mode.
Source File:
rtcc.h
Coding Example:
mRtccFreezeDisable ();
mRtccGetFreeze
Description:
Include:
plib.h
Prototype:
bool mRtccGetFreeze(void);
Arguments:
None
Return Value:
Remarks:
Source File:
rtcc.h
Coding Example:
int main(void)
{
rtccTimetm, tm1, tAlrm;// time structure
rtccDatedt, dt1, dAlrm;// date structure
// Configure the device for maximum performance.
// This macro sets flash wait states, PBCLK divider and DRM wait states based on the specified
// clock frequency. It also turns on the cache mode if avaialble.
// Based on the current frequency, the PBCLK divider will be set at 1:2. This knoweldge
// is required to correctly set UART baud rate, timer reload value and other time sensitive
// setting.
SYSTEMConfigPerformance(72000000L);
RtccInit();
while(RtccGetClkStat()!=RTCC_CLK_ON);
// wait for the SOSC to be actually running and RTCC to have
// its clock source. Could wait here at most 32ms
// when using the RtccSetTimeDate() function, the write operation is enabled if needed and
// then restored to the initial value
// so that we don't have to worry about calling RtccWrEnable()/mRtccWrDisable() functions
// let's start setting the current date
// one way to do it
tm.l=0;
tm.sec=0x30;
tm.min=0x07;
tm.hour=0x10;
dt.wday=2;
dt.mday=0x16;
dt.mon=0x01;
dt.year=0x07;
RtccSetTimeDate(tm.l, dt.l);
// however, much easier to do it should be:
RtccSetTimeDate(0x10073000, 0x07011602);
// time is MSb: hour, min, sec, rsvd. date
// date is MSb: year, mon, mday, wday.
// please note that the rsvd field has to be 0 in the time field!
// NOTE: at this point the writes to the RTCC time and date registers are disabled
// we can also read the time and date
tm1.l=RtccGetTime();
dt1.l=RtccGetDate();
// or we can read the time and date in a single operation
RtccGetTimeDate(&tm1, &dt1);
// now that we know the RTCC clock is up and running, it's easier to start from fresh:
RtccOpen(tm.l, dt.l, 0);// set time, date and calibration in a single operation
// check that the RTCC is running
{
int isRunning;
long retries;
int secCnt;
dAlrm.l=dt.l;
tAlrm.sec+=2;// alarm due in 2 secs
RtccChimeDisable();// don't want rollover
RtccSetAlarmRptCount(0);// one alarm will do
RtccSetAlarmRpt(RTCC_RPT_TEN_SEC);// enable repeat rate, check the second field
RtccSetAlarmTimeDate(tAlrm.l, dAlrm.l);// set the alarm time
RtccAlarmEnable();// enable the alarm
while(RtccGetAlarmEnable());// wait it to be cleared automatically
// other things we may do with the alarm...
RtccChimeEnable();// enable indefinite repeats
RtccSetAlarmRptCount(1);// set the initial repeat count
RtccSetAlarmRpt(RTCC_RPT_MIN);// enable repeat rate, every minute, for ex
RtccAlarmDisable();// disable the alarm
int isAlrmEn=RtccGetAlarmEnable();// check that the alarm is enabled
// other RTCC operations
// adjust the RTCC timing
RtccSetCalibration(200);// value to calibrate with at each minute
// enabling the RTCC output pin
mRtccSelectSecPulseOutput();
// select the seconds clock pulse as the function of the RTCC output pin
mRtccSelectAlarmPulseOutput(); // select the alarm pulse as the RTCC output pin
mRtccOutputEnable();
mRtccClrIntFlag();
}
// we can check to see if the RTCC interrupts are enabled:
int isRtccIntEn=mRtccGetIntEnable();
return 1;
}
18.0
ADC10 FUNCTIONS
The PIC32MX has an ADC with multiple mode and configuration options. The ADC
library functions are available to allow high-level control of the ADC. The following
functions and macros are available:
18.1
Individual Functions
There are no functions to support this module, refer to the macro section
18.2
Individual Macros
AcquireADC10
Description:
Include:
plib.h
Prototype:
AcquireADC10();
Arguments:
None
Return Value:
None
Remarks:
This macro sets the ADCON1<SAMP> bit and thus starts sampling.
This happens only when trigger source for the A/D conversion is
selected as Manual, by clearing the ADCON1 <SSRC> bits.
Code Example:
ConvertADC10();
BusyADC10
Description:
Include:
plib.h
-page 291
int BusyADC10();
Arguments:
None
Return Value:
Remarks:
None
Code Example:
while(BusyADC10());
CloseADC10
Description:
This macro turns off the ADC module and disables the ADC interrupts.
Include:
plib.h
Prototype:
CloseADC10();
Arguments:
None
Return Value:
None
Remarks:
This function first disables the ADC interrupt and then turns off the ADC
module.The Interrupt Flag bit (ADIF) is also cleared.
Code Example:
CloseADC10();
ConfigIntADC10
Description:
Include:
plib.h
Prototype:
Arguments:
config
Return Value:
-page 292
None
ConfigIntADC10
Remarks:
This function clears the Interrupt Flag (ADIF) bit and then sets the
interrupt priority and enables/disables the interrupt.
Code Example:
ConfigIntADC10(ADC_INT_PRI_3 | ADC_INT_SUB_PRI_3 |
ADC_INT_ENABLE);
ConvertADC10
Description:
Include:
plib.h
Prototype:
ConvertADC10();
Arguments:
None
Return Value:
None
Remarks:
This function clears the ADCON1<SAMP> bit and thus stops sampling
and starts conversion.
Code Example:
ConvertADC10();
EnableADC10
Description:
Include:
plib.h
Prototype:
EnableADC10();
Arguments:
None
Remarks:
This macro is intended for use when the ADC is configured but not
enabled by prior operations. The ADC configuration should not be
changed while the ADC is enabled.
Code Example:
EnableADC10();
OpenADC10
Description:
This function configures the ADC using the 5 parameters passed to it.
Include:
plib.h
Prototype:
void OpenADC10(unsigned
unsigned
unsigned
unsigned
unsigned
Arguments:
config1
long
long
long
long
long
int
int
int
int
int
config1,
config2,
config3,
configport,
configscan)
-page 293
-page 294
OpenADC10
Number of samples between interrupts
ADC_SAMPLES_PER_INT_1
ADC_SAMPLES_PER_INT_2
.....
ADC_SAMPLES_PER_INT_15
ADC_SAMPLES_PER_INT_16
(These bit fields are mutually
exclusive)
Buffer mode select
ADC_ALT_BUF_ON
ADC_ALT_BUF_OFF
(These bit fields are mutually
exclusive)
Alternate Input Sample mode select
ADC_ALT_INPUT_ON
ADC_ALT_INPUT_OFF
(These bit fields are mutually
exclusive)
config3
-page 295
configscan
Return Value:
None
Remarks:
Code Example:
OpenADC10(ADC_MODULE_OFF |
ADC_IDLE_STOP |
ADC_FORMAT_SIGN_FRACT16 |
ADC_CLK_INT0 |
ADC_SAMPLE_INDIVIDUAL |
ADC_AUTO_SAMPLING_ON,
ADC_VREF_AVDD_AVSS |
ADC_SCAN_OFF |
ADC_ALT_INPUT_ON |
ADC_SAMPLES_PER_INT_10,
ADC_SAMPLE_TIME_4 |
ADC_CONV_CLK_PB |
ADC_CONV_CLK_Tcy,
ENABLE_AN1_ANA,
SKIP_SCAN_AN0 |
SKIP_SCAN_AN3 |
SKIP_SCAN_AN4 |
SKIP_SCAN_AN5);
ReadActiveBufferADC10
-page 296
Description:
Include:
plib.h
Prototype:
ReadActiveBufferADC10();
Arguments:
None
ReadActiveBufferADC10 (Continued)
Remarks:
This macro is intended for use when the ADC output buffer is is used in
dual buffer mode. A 0 result indicates that buffer locations 0-7 are
being written by the ADC module. A 1 result indicates that buffer
locations 8-F are being written by the ADC module.
Code Example:
-page 297
This function reads the specified entry in the ADC result buffer which
contains the conversion value.
Include:
plib.h
Prototype:
Arguments:
bufIndex
Return Value:
Remarks:
This function returns the contents of the ADC Buffer register. User
should provide bufIndex value between 0 to 15 to ensure a correct
read of AD1CBUF0 through AD1CBUFF.
Code Example:
SetChanADC10
Description:
This function sets the positive and negative inputs for the sample
multiplexers A and B for manual and alternate sample modes.
Include:
plib.h
Prototype:
Arguments:
channel
-page 298
Return Value:
None
Remarks:
SetChanADC10 (Continued)
Code Example:
SetChanADC10(ADC_CH0_POS_SAMPLEA_AN0 |
ADC_CH0_NEG_SAMPLEA_NVREF);
-page 299
Example of Use
ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_12
#define PARAM4SKIP_SCAN_ALL
#define PARAM5ENABLE_AN4_ANA | ENABLE_AN5_ANA
// configure to sample AN4 & AN5
SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN4 |
ADC_CH0_NEG_SAMPLEB_NVREF | ADC_CH0_POS_SAMPLEB_AN5);
// configure ADC and enable it
OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 );
// Now enable the ADC logic
EnableADC10();
// the results of the conversions are available in channel4 and channel5
while (1)
{
// determine which buffer is idle and create an offset
offset = 8 * ((~ReadActiveBufferADC10() & 0x01));
// read the result of channel 4 conversion in the idle buffer
channel4 = ReadADC10(offset);
// read the result of channel 5 conversion in the idle buffer
channel5 = ReadADC10(offset + 1);
}
}
-page 300
19.0
COMPARATOR FUNCTIONS
The PIC32MX has analog comparataors with multiple configuration options. The comparator library functions are available to allow high-level control of the comparators.
The following macros are available:
CMP1Close(), CMP2Close() - Disables the comparators interrupt and turns off both
comparators.
CMP1ConfigInt(), CMP2ConfigInt() - Configures the interrupt for the comparator.
CMP1Open(), CMP2Open() - Configures the comparator inputs, and event generation.
CMP1Read(), CMP2Read() - Reads the status of the comparator output bit.
19.1
Individual Functions
There are no functions to support this module, refer to the macro section
19.2
Individual Macros
CMP1Close()
CMP2Close()
Description:
Include:
plib.h
Prototype:
CMP1Close();
CMP2Close();
Arguments:
None
Return Value:
None
Remarks:
This function turns the CMP module off and disables the interrupt.
Code Example:
CMP1Close();
CMP1Open()
CMP2Open()
Description:
Include:
plib.h
Prototype:
Arguments:
config
-page 301
-page 302
Return Value:
None
Remarks:
Code Example:
CMP1Open(CMP_ENABLE | CMP_HALT_IN_IDLE |
CMP_OUTPUT_ENABLE | CMP_OUTPUT_INVERT |
CMP_EVENT_LOW_TO_HIGH | CMP_POS_INPUT_CVREF |
CMP_NEG_INPUT_CINC);
CMP1IntConfig()
CMP2Intconfig()
Description:
Include:
plib.h
Prototype:
CMP1IntConfig();
CMP2IntConfig();
Arguments:
config
Return Value:
Remarks:
Code Example:
CMP1Read()
CMP2Read()
Description:
Include:
plib.h
Prototype:
CMP1Read();
CMP2Read();
Arguments:
None
Return Value:
None
Remarks:
Code Example:
-page 303
Example of Use
#inlcude <plib.h>
int main(void)
{
unsigned int status;
// Configure comparator 1
CMP1Open( CMP_ENABLE | CMP_OUTPUT_NONINVERT | CMP_EVENT_NONE |
CMP_POS_INPUT_C1IN_POS | CMP1_NEG_INPUT_C1IN_NEG );
while ( 1 )
{
status = CMP1Read(); //get the current status of the comparator
}
return 0;
}
-page 304
20.0
CVREF FUNCTIONS
The PIC32MX has comparator voltage reference with multiple configuration options.
The CVREF library functions are available to allow high-level control of the module.
The following macros are available:
CVREFClose() - Disables the CVREF module and disable the output pin.
CVREFOpen() - Enables the CVREF module. Sets the output voltage, configure the
output range, and configures the output to a pin.
20.1
Individual Functions
There are no functions to support this module, refer to the macro section
20.2
Individual Macros
CVREFClose()
Description:
Include:
plib.h
Prototype:
CVREFClose();
Arguments:
None
Return Value:
None
Remarks:
This function turns the CVREF module off and disables the output.
Code Example:
CVREFClose();
CVREFOpen()
Description:
Include:
plib.h
Prototype:
Arguments:
config
-page 305
None
Remarks:
Code Example:
-page 306
CVREFOpen(CVREF_ENABLE | CVREF_OUTPUT_ENABLE
CVREF_RANGE_HIGH | CVREF_SOURCE_AVDD |
CVREF_STEP_15);
20.3
Example of Use
-page 307
-page 308
21.0
WDT FUNCTIONS
This section contains a list of individual functions for the WatchDog Timer and an example of use
of the functions. Functions may be implemented as macros.
21.1
Individual Functions
There are no functions to support this module, refer to the macro section
21.2
Individual Macros
DisableWDT()
Description:
Include:
plib.h
Arguments:
None
Prototype:
void DisableWDT(void);
Return Value:
None
Remarks:
The WDT can only be disabled in software if it was not enabled by the
WDT fuse.
Code Example:
DisableWDT();
EnableWDT()
Description:
Include:
plib.h
Prototype:
void EnableWDT(void);
Arguments:
Mode
Return Value:
None
Remarks:
Code Example:
EnableWDT();
ClearWDT()
Description:
Include:
plib.h
Arguments:
None
Prototype:
void ClearWDT(void);
Return Value:
None
Remarks:
Code Example:
ClearWDT();
-page 309
ClearEventWDT()
Description:
Include:
plib.h
Arguments:
None
Prototype:
void ClearEventWDT(void);
Return Value:
None
Remarks:
This function allows the WDT event bit to be reset after the startup code
has determined the souce of the device reset.
Code Example:
ClearEventWDT();
ReadEventWDT()
Description:
Include:
plib.h
Arguments:
None
Prototype:
Return Value:
Remarks:
Code Example:
ReadPostscalerWDT()
Description:
Include:
plib.h
Arguments:
None
Prototype:
Return Value:
Remarks:
Code Example:
-page 310