EasyManua.ls Logo

Freescale Semiconductor MPC5604B - Chapter 10 UART: Universal Asynchronous Receiver Transmitter; 1. Introduction to UART; 2. Module Presentation

Default Icon
150 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
An array transfer method called with an array size of ‘1’ is pretty much equivalent to a single
data transfer (with a few excessive useless clock cycles). Each time a transfer is completed a
‘Completed’ flag in the driver structure is set to 1 and it is automatically cleared when a new
transfer method is called. The driver sets the pins automatically according to its slave/master
needs.
Example:
There are some constant defines for quick initialisation of the system. Every possible I/O ports
are on the header file and can be selected before compilation.
Example:
Similarly, maximum authorised data array transfer size, data frame size are defined as constants
that can be altered. Some typical baud rates and transfer delays are defined as constants for a
system clock of 64MHz and use can define their own constants by following the explanations on
the driver documentation.
Transfer methods that can run on the background use transfer complete interrupts, and a finite
state machine has been implemented for executing different handlers depending on the transfer
method that is used. The user is free to add their own states for their own handling needs and
modify other methods accordingly.
struct _SPI_DRV SPI[]; //SPI variable has to be imported from the SPI
//Driver module
uint16_t RxData[128]; //An array for storing received data
int main(void) {
initModesAndClks(); //remember to enable DSPI module with PCTL registers,
//
and set Sys_Clk(=Peripheral_Clock) to 64MHz if you
//wish to use predefined baud-rates
initPeriClkGen();
disableWatchdog();
initialise_SPI_DRIVER(); //must be called before using the driver
enableIrq();
SPI[0].init(SPI_BAUD_62500, SPI_DELAY_DEFAULT);
//Initialize SPI module
//you wish to use, in this example PORT_A of DSPI0 is defined
SPI[1].init(SPI_BAUD_62500, SPI_DELAY_DEFAULT);
//and PORT_E of DSPI1,
and they are connected with jumper wires.
SPI[0].listen(RxData, 4,1);
SPI[1].write_array((uint16_t*)"Coucou!\0",4,1);
//Both modules are running on the background, 'write array' gets the next
//half word when the current one is transmitted and 'listen' manages the
//RX array storage.
while (!(SPI[0].Completed && SPI[1].Completed)){}
while (1) {} //End of program
}
#define DSPI0_PORT 'A'
#define DSPI1 PORT 'C'

Table of Contents

Other manuals for Freescale Semiconductor MPC5604B

Related product manuals